3 <title>mikers experimental opensearch portal</title>
7 font-family: verdana,arial,helvetica,sans-serif;
14 text-decoration: none;
22 border: solid black 1px;
26 border: solid lightblue 1px;
27 background-color: lightblue;
32 text-decoration: none;
37 text-decoration: underline;
42 text-decoration: underline;
47 text-decoration: none;
64 border-collapse: collapse;
65 border: solid gray 1px;
69 border-collapse: collapse;
73 max-width: 300px !important;
74 min-width: 200px !important;
78 max-width: 100% !important;
82 max-width: 100% !important;
83 min-width: 400px !important;
87 border-bottom: 1px dashed darkgrey;
100 function create_requestor () {
103 req = new ActiveXObject("Msxml2.XMLHTTP");
107 req = new ActiveXObject("Microsoft.XMLHTTP");
114 if (!req && typeof XMLHttpRequest!='undefined') {
115 req = new XMLHttpRequest();
119 alert("NEEDS NEWER JAVASCRIPT for XMLHTTPRequest()");
126 var proxy = 'http://gapines.org/opensearch/?fetch=';
131 var search_templates = [];
132 var search_urls = {};
135 var current_startPage = 1;
136 var current_startIndex = 1;
137 var current_count = 5;
139 function opensearch ( term, reset, single_source ) {
142 current_startPage = 1;
148 create_search(single_source);
149 var turi = search_templates[single_source].replace(/\{searchTerms\}/,encodeURIComponent(term));
150 turi = turi.replace(/\{startPage\}/,current_startPage);
151 turi = turi.replace(/\{startIndex\}/,current_startIndex);
152 turi = turi.replace(/\{count\}/,current_count);
153 turi = turi.replace(/\{relevanceScale}/,'0');
154 search_urls[single_source] = proxy + encodeURIComponent(turi);
157 var cur_src = document.getElementById('result_sources');
158 for (var i = 1; i < cur_src.childNodes.length; i++) {
159 if (cur_src.childNodes[i].textContent == turi)
162 cur_src.innerHTML += '<a name="' + single_source + '" href="' + turi + '">' + turi + '</a><br>';
163 perform_search(single_source);
167 document.getElementById('next_button').className = 'hide';
169 if (current_startPage == 1)
170 document.getElementById('prev_button').className = 'hide';
172 document.getElementById('prev_button').className = '';
174 var tot = document.getElementById('total');
175 while (tot.lastChild)
176 tot.removeChild(tot.lastChild);
178 var src = document.getElementById('result_sources');
179 while (src.lastChild)
180 src.removeChild(src.lastChild);
182 document.getElementById('int_res_hide').className = 'noshow';
183 document.getElementById('col_res_hide').className = 'noshow';
185 var tab = document.getElementById('int_res');
186 while (tab.lastChild)
187 tab.removeChild(tab.lastChild);
189 tab = document.getElementById('col_res');
190 while (tab.lastChild)
191 tab.removeChild(tab.lastChild);
195 var sources = new Array();
196 var selector = document.getElementsByName('source');
197 for (var i = 0; i < selector.length; i++) {
198 if (selector[i].checked) {
199 sources.push(selector[i].value);
203 search_templates = [];
204 for (var i in sources) {
205 create_search( sources[i] );
208 current_startIndex = (current_count * (current_startPage - 1)) + 1;
211 for (var i in search_templates) {
212 if (!search_templates[i])
218 var url = search_templates[i].replace(/\{searchTerms\}/,encodeURIComponent(term));
219 url = url.replace(/\{startPage\}/,current_startPage);
220 url = url.replace(/\{startIndex\}/,current_startIndex);
221 url = url.replace(/\{count\}/,current_count);
222 url = url.replace(/\{relevanceScale}/,rel_scales[i]);
223 search_urls[i] = proxy + encodeURIComponent(url);
225 src.innerHTML += '<a name="' + i + '" href="' + url + '">' + url + '</a><br>';
228 for (var i in search_urls) {
229 if (!search_templates[i])
235 document.getElementById('page_label').innerHTML = current_startPage;
238 function perform_search ( source ) {
239 var req = create_requestor();
241 req.onreadystatechange = function () {
242 if (req.readyState != 4)
245 var xml = req.responseXML;
247 var desc = getElementTextNS('','description',xml,0);
248 var xml_link = getElementTextNS('','link',xml,0);
250 var total = getElementFloatNS('openSearch','totalResults',xml,0);
251 var integratible = (getElementNS('openIll','relevance',xml,0) != null);
252 var scale = getElementFloatNS('openIll','relevanceScale',xml,0);
254 rel_scales[source] = scale;
256 var tot = document.getElementById('total');
257 var current_tot = parseFloat(tot.textContent);
258 var res_type = document.getElementById('res_type');
260 if (res_type.options[res_type.selectedIndex].value == 'col')
266 if (total > (current_startPage * current_count))
267 document.getElementById('next_button').className = '';
270 tot.innerHTML = current_tot;
272 var list = xml.getElementsByTagName('item');
273 for (var i = 0; i < list.length; i++) {
275 if ( typeof list[i] != 'object')
280 tab = document.getElementById('col_res');
281 document.getElementById('col_res_hide').className = '';
282 var col = document.getElementById(source);
284 var row = tab.rows[0];
286 row = tab.insertRow(0);
288 col = document.createElement('td');
289 col.setAttribute('id',source);
290 col.setAttribute('name',source);
291 row.appendChild(col);
293 tab = document.createElement('table');
294 tab.setAttribute('valign','top');
295 tab.setAttribute('class','col_tab');
297 var cap = document.createElement('caption');
298 tab.appendChild(cap);
299 cap.innerHTML = desc + ' -- <a href="' + xml_link + '">XML</a>';
301 col.appendChild(tab);
303 var per = parseInt(100 / (search_urls.length * 2)) - 1;
304 col.setAttribute('valign','top');
305 col.setAttribute('width', + per + '%');
308 tab = col.firstChild;
311 tab = document.getElementById('int_res');
312 document.getElementById('int_res_hide').className = '';
315 if (!tab.rows.length) {
316 add_result_row(tab, 0, list[i], source);
318 for (var j = 0; j < tab.rows.length; j++) {
319 if ( typeof tab.rows[j] != 'object')
324 rank = getElementFloatNS('openIll','relevance',list[i],0);
326 alert("error getting float relevance: " + e);
330 if ( rank < parseFloat(tab.rows[j].firstChild.firstChild.textContent) ) {
331 if ( (j + 1) == tab.rows.length) {
332 add_result_row(tab, tab.rows.length, list[i], source);
337 add_result_row(tab, j, list[i], source);
344 req.open('GET', proxy + encodeURIComponent(search_urls[source]), true);
349 // retrieve float of an XML document element, including
350 // elements using namespaces
351 function getElementFloatNS(prefix, local, parentElem, index) {
352 var result = getElementNS(prefix, local, parentElem, index);
354 // get text, accounting for possible
355 // whitespace (carriage return) text nodes
356 if (result.childNodes.length > 1) {
357 return parseFloat(result.childNodes[1].nodeValue);
359 return parseFloat(result.textContent);
366 function getElementNS(prefix, local, parentElem, index) {
368 if (prefix && isIE) {
369 // IE/Windows way of handling namespaces
370 return parentElem.getElementsByTagName(prefix + ":" + local)[index];
372 // the namespace versions of this method
373 // (getElementsByTagNameNS()) operate
374 // differently in Safari and Mozilla, but both
375 // return value with just local name, provided
376 // there aren't conflicts with non-namespace element
378 return parentElem.getElementsByTagName(local)[index];
382 // retrieve text of an XML document element, including
383 // elements using namespaces
384 function getElementTextNS(prefix, local, parentElem, index) {
385 var result = getElementNS(prefix, local, parentElem, index);
387 // get text, accounting for possible
388 // whitespace (carriage return) text nodes
389 if (result.childNodes.length > 1) {
390 return result.childNodes[1].nodeValue;
392 return result.firstChild.nodeValue;
399 function add_result_row (tab, index, xml, source) {
400 var img = images[source];
401 var rank,title,tlink,desc;
404 rank = getElementFloatNS('openIll','relevance',xml,0);
406 alert("error getting relevance: " + e);
411 title = getElementTextNS('','title',xml,0);
417 tlink = getElementTextNS('','link',xml,0);
423 description = getElementTextNS('','description',xml,0);
428 var row = tab.insertRow(index);
429 row.setAttribute('name',source);
430 row.className = 'res_tr';
431 row.innerHTML = '<td style="padding: 4px"><div style="display: none; visibility: hidden;">' + rank +
432 '</div><span class="title_link"><a href="' + tlink + '">' + title +
433 '</a></span><br/><span class="desc_text">' + description + '</span></td>' +
434 '<td><img title="' + parseInt(rank) + '% Relevant" width="32" height="32" src="' + img + '"></td>';
437 function create_search ( s ) {
438 var req = create_requestor();
440 req.open('GET',proxy + encodeURIComponent(s),false);
444 var xml = req.responseXML;
445 search_templates[s] = xml.getElementsByTagName('Url')[0].textContent;
446 var i = xml.getElementsByTagName('Image');
448 images[s] = i[0].textContent;
449 return search_templates[s];
451 alert('BAD XML!\n\n' + e + '\n\n' + req.responseText);
452 search_templates[s] = null;
458 function remove_by_name( src ) {
459 var list = document.getElementsByName(src);
461 var len = list.length;
464 list[0].parentNode.removeChild(list[0]);
472 <table style="border-collapse: collapse; margin: 5px;" width="100%">
473 <tr style="border-bottom: dotted black 1px;" valign="top">
474 <td align="right">Keyword Search: </td>
476 <input type="text" id="term" value="javascript"/>
477 <input type="submit" value="Go!" onclick="insearch=true; opensearch(document.getElementById('term').value, true); return false;"/>
479 <td align="left">Hits per Source for each page:
480 <select onchange="current_count=this.options[this.selectedIndex].value;">
481 <option value="5" selected>5</option>
482 <option value="10">10</option>
483 <option value="25">25</option>
486 <td align="left">Display style:
487 <select id="res_type">
488 <option value="int" selected>Merged Results</option>
489 <option value="col">Separate Columns</option>
493 <tr style="border-bottom: dotted black 1px;" valign="top">
494 <td align="right">Sources: </td>
496 <table width="100%" style="border-collapse: collapse;">
499 <label class="source_input">
504 opensearch(document.getElementById('term').value, false, this.value);
506 remove_by_name(this.value);
511 value="http://gapines.org/opensearch.xml"
516 <label class="source_input">
521 opensearch(document.getElementById('term').value, false, this.value);
523 remove_by_name(this.value);
528 value="http://rsinger.library.gatech.edu/opensearch/osdd-gil.xml"
529 checked>GIL Universal Catalog
533 <label class="source_input">
538 opensearch(document.getElementById('term').value, false, this.value);
540 remove_by_name(this.value);
545 value="http://search.athenscounty.lib.oh.us/cgi-bin/koha/opensearchdescription">NPL/Koha
549 <label class="source_input">
554 opensearch(document.getElementById('term').value, false, this.value);
556 remove_by_name(this.value);
561 value="http://www.koders.com/search/KodersSourceCodeSearchDescription.xml">Koders Source Code
568 <label class="source_input">
573 opensearch(document.getElementById('term').value, false, this.value);
575 remove_by_name(this.value);
580 value="http://cnx.rice.edu/content/opensearchdescription">rice.edu Connexions
584 <label class="source_input">
589 opensearch(document.getElementById('term').value, false, this.value);
591 remove_by_name(this.value);
596 value="http://redlightgreen.com/ucwprod/web/opensearchDescription.xml">RedLightGreen
600 <label class="source_input">
605 opensearch(document.getElementById('term').value, false, this.value);
607 remove_by_name(this.value);
612 value="http://www.itpapers.com/itpaperssearchdescription.xml">ITPapers
616 <label class="source_input">
621 opensearch(document.getElementById('term').value, false, this.value);
623 remove_by_name(this.value);
628 value="http://lib-cufts.lib.sfu.ca/CUFTS/opensearchjournal.xml">SFU CUFTS
631 <!-- <input name="source" type="checkbox" value="http://www.webdevref.com/blog/opensearchdescription.xml">WebDefRef -->
637 <td>Total results: </td>
638 <td colspan=2 id="total"></td>
641 <td>Current page: </td>
642 <td id="page_label"></td>
648 if (this.className != 'hide') {
649 current_startPage -= 1;
650 opensearch(document.getElementById('term').value);
652 return false;">Previous Page
658 if (this.className != 'hide') {
659 current_startPage += 1;
660 opensearch(document.getElementById('term').value);
662 return false;">Next Page
671 <table id="results" width="100%">
673 <td id="int_res_hide" class="noshow" width="100%">
675 <caption class="header">Merged search results</caption>
678 <table id='int_res' class="res_table" width="100%"></table>
683 <td id='col_res_hide' class="noshow">
685 <caption class="header">Unranked search results</caption>
688 <table id='col_res' class="res_table"></table>
695 <div id="result_sources"></div>