annotate templates.swigs/search.js @ 0:a84c32f131df 1.1.29

Import vendor version
author Peter Gervai <grin@grin.hu>
date Wed, 15 Oct 2008 23:28:56 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
1
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
2 /* contains all the data about the pictures (set after the page is
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
3 loaded) */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
4 var search_data;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
5
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
6 function get_query_variable(variable) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
7 var query = window.location.search.substring(1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
8 var vars = query.split("&");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
9 for (var i=0;i<vars.length;i++) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
10 var pair = vars[i].split("=");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
11 if (pair[0] == variable) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
12 return pair[1];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
13 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
14 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
15 return '';
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
16 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
17
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
18 /* Remove the loading message and get the search data
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
19 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
20 function page_loaded() {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
21 search_data = sd;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
22
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
23 if (document.getElementById){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
24 document.getElementById('loading').style.visibility='hidden';
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
25 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
26 if (document.layers){ //NS4
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
27 document.loading.visibility = 'hidden';
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
28 } else { //IE4
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
29 document.all.loading.style.visibility = 'hidden';
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
30 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
31 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
32 search_string = decodeURIComponent(get_query_variable('q'));
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
33 set_search_string(search_string);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
34 var word_search = get_query_variable('w');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
35 if (word_search=='1') {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
36 word_search = true;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
37 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
38 word_search = false;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
39 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
40 document.getElementById('search_word').checked = word_search;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
41 perform_search(search_string, word_search);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
42
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
43 if (document.layers) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
44 document.captureEvents(Event.KEYPRESS);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
45 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
46 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
47
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
48 /* Return a copy of str, translating all occurrences of each character
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
49 in from to the corresponding character in to
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
50 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
51 String.prototype.strtr = function(from, to)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
52 {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
53 var s, p, c1, c2, c3;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
54 if(! this.length || from.length != to.length) return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
55
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
56 s = this;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
57 for(var i=0; i < this.length; i++) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
58 c1 = this.substr(i,1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
59 for(var j=0; j<from.length; j++) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
60 c2 = from.substr(j,1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
61 c3 = to.substr(j,1);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
62 if(c1 == c2) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
63 p = new RegExp(c2,'gi');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
64 s = s.replace(p,c3);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
65 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
66 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
67 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
68 return s;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
69 };
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
70
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
71 /* Return a copy of str, removing all accents in it
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
72 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
73 function remove_accents(string) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
74 return string.strtr(
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
75 "?????????????????????????????????????????????????????????",
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
76 "AAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
77 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
78
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
79
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
80 /* set the string in the query input
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
81 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
82 function set_search_string(search_string) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
83 var input = document.getElementById('search_string');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
84 input.value = search_string;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
85 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
86
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
87 /* return the string entered by the user, normalized
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
88 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
89 function get_search_string() {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
90 var input = document.getElementById('search_string');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
91 var search_string = remove_accents(input.value.toLowerCase());
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
92
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
93 return search_string;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
94 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
95
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
96 /* return a list of keywords from the string entered by user
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
97 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
98 function get_keywords(search_string, word_search) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
99 if (! search_string ) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
100 return new Array;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
101 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
102 keywords = search_string.split(/[^a-z0-9]+/i);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
103
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
104 var result = new Array;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
105 for (var i=0; i<keywords.length; i++) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
106 if (keywords[i]) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
107 if (word_search) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
108 result[result.length] = " " + keywords[i] + " ";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
109 } else {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
110 result[result.length] = keywords[i];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
111 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
112 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
113 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
114 return result;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
115 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
116
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
117 /* replace a %parameter% in the template by its value
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
118 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
119 function set_value(template, parameter, value) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
120 re = new RegExp("%"+parameter+"%", "g");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
121 return template.replace(re, value)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
122 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
123
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
124 /* display one found result in the page
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
125 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
126 function display_result(results, image) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
127 result = result_html;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
128 result = set_value(result, 'url', image.url);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
129 result = set_value(result, 'thumb_url', image.thumb_url);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
130 result = set_value(result, 'album_url', image.album_url);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
131 result = set_value(result, 'album_title', image.album_title);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
132 result = set_value(result, 'title', image.title);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
133 result = set_value(result, 'thumb_width', image.width);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
134 result = set_value(result, 'thumb_height', image.height);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
135
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
136 results.innerHTML += result;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
137 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
138
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
139 /* update the status string on the page
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
140 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
141 function update_status(status, found) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
142 status.firstChild.nodeValue = "Search in progress: " + found.toString() +" found";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
143 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
144
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
145 /* return true if all keywords (array of string) match the string s
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
146 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
147 function match(keywords, s){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
148 for (var i=0 ; i<keywords.length ; i++) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
149 if (keywords[i] && s.indexOf(keywords[i]) == -1) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
150 return false;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
151 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
152 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
153 return true;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
154 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
155 /* perform the search when the page is loaded
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
156 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
157 function perform_search(search_string, word_search) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
158
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
159 if (! (document.getElementById || document.createElement)){
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
160 alert("<TMPL_VAR NAME=STRING_NODOM>");
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
161 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
162 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
163
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
164 var limit = <TMPL_VAR NAME=SEARCH_LIMIT>;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
165 var found = 0;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
166 var keywords = get_keywords(search_string, word_search);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
167 if (keywords.length == 0) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
168 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
169 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
170 var results = document.getElementById('results');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
171 results.innerHTML = "";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
172 var status = document.getElementById('status');
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
173
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
174 update_status(status, found);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
175
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
176 for (var i=0 ; i<search_data.length; i++) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
177 image = search_data[i];
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
178 if (match(keywords, image.search_string)) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
179 if (found >= limit) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
180 var status_string = "<TMPL_VAR NAME=STRING_TOOMANYRESULTS>";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
181 // WTF ? Not sprintf in javascript ? OK, so I code dirty
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
182 status_string = status_string.replace(/%d/, found.toString());
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
183 status.firstChild.nodeValue = status_string;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
184 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
185 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
186
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
187 update_status(status, found++);
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
188 display_result(results, image)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
189 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
190 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
191 var status_string = "<TMPL_VAR NAME=STRING_SEARCHCOMPLETED>";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
192 // For dirty hacking remark, see above comment
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
193 status_string = status_string.replace(/%d/, found.toString());
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
194 status.firstChild.nodeValue = status_string;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
195 return;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
196 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
197
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
198 /* if user has pressed return in the input field, validate the search
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
199 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
200 function process_key(e) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
201 if (window.event) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
202 if (window.event.type == "keypress" & window.event.keyCode == 13)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
203 reload_page();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
204 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
205 if (e) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
206 if (e.type == "keypress" & e.keyCode == 13) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
207 reload_page();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
208 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
209 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
210 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
211
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
212 /* Reload the page when the user click the search button
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
213 */
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
214 function reload_page() {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
215 var search_string = get_search_string();
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
216 var word_search = document.getElementById('search_word').checked;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
217 if (search_string) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
218 search_string = encodeURIComponent(search_string)
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
219 if (word_search) {
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
220 search_string += "&w=1";
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
221 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
222 location.href = location.pathname + "?q=" + search_string;
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
223 }
a84c32f131df Import vendor version
Peter Gervai <grin@grin.hu>
parents:
diff changeset
224 }