/[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 396 - (hide annotations)
Thu Jul 22 19:00:27 2004 UTC (19 years, 9 months ago) by dpavlin
File MIME type: application/javascript
File size: 2602 byte(s)
JavaScript sucks: re-implemented unescape to produce ISO-8859-2 charset
(and not ISO-8859-2), unac function to remove accented characters from
ISO-8859-2, use l2_unescape, new results output

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 dpavlin 394 var pattern = /query=/i;
20 dpavlin 396 var url_args;
21    
22     //alert("referer: "+document.referrer+" location.search: "+location.search.substring(1));
23    
24     if (pattern.exec(document.referrer) != null) {
25 dpavlin 393 var url_parts = document.referrer.split('?');
26 dpavlin 396 if (url_parts[1]) url_args = url_parts[1];
27     } else if (pattern.exec(location.search.substring(1)) != null) {
28     url_args = location.search.substring(1);
29     alert(url_args);
30     }
31    
32     if (url_args){
33     var url_args = url_args.split('&');
34     for(var i=0; i<url_args.length; i++){
35     var keyval = url_args[i].split('=');
36     if (keyval[0] == 'query'){
37     go_google(decode_url(keyval[1]));
38     return;
39 dpavlin 393 }
40     }
41     }
42     }
43    
44     function decode_url(url){
45 dpavlin 396 return l2_unescape(url.replace(/\+/g,' '));
46 dpavlin 393 }
47    
48     function go_google(terms){
49     terms = terms.replace(/\"/g,"");
50     var terms_split = terms.split(' ');
51     var c = 0;
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     }
56     }
57    
58     function highlight_goolge(term, container, color){
59     var term_low = term.toLowerCase();
60    
61     for(var i=0; i<container.childNodes.length; i++){
62     var node = container.childNodes[i];
63    
64     if (node.nodeType == 3){
65     var data = node.data;
66     var data_low = data.toLowerCase();
67     if (data_low.indexOf(term_low) != -1){
68     //term found!
69     var new_node = document.createElement('SPAN');
70     node.parentNode.replaceChild(new_node,node);
71     var result;
72     while((result = data_low.indexOf(term_low)) != -1){
73     new_node.appendChild(document.createTextNode(data.substr(0,result)));
74     new_node.appendChild(create_node_google(document.createTextNode(data.substr(result,term.length)),color));
75     data = data.substr(result + term.length);
76     data_low = data_low.substr(result + term.length);
77     }
78     new_node.appendChild(document.createTextNode(data));
79     }
80     }else{
81     //recurse
82     highlight_goolge(term, node, color);
83     }
84     }
85     }
86    
87     function create_node_google(child, color){
88     var node = document.createElement('SPAN');
89     node.style.backgroundColor = color;
90     node.style.color = google_text_color;
91     node.appendChild(child);
92     return node;
93     }

  ViewVC Help
Powered by ViewVC 1.1.26