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

Contents of /trunk2/out/js/highlight.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 474 - (show annotations)
Sun Sep 26 17:57:21 2004 UTC (19 years, 6 months ago) by dpavlin
File MIME type: application/javascript
File size: 2395 byte(s)
fixed warning

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

  ViewVC Help
Powered by ViewVC 1.1.26