X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=www%2Fdemo%2Fsearch.js;h=636b6e64cddfe3834be3191c458ae865dfbdd3b5;hb=43ab7355ebcec6bad9904067a1cfe46ccf1a9b0c;hp=41b19b521ec787726309b98b72a80e78e924661a;hpb=015261c103f2b4f8e4d06220605a2053e52a1249;p=pazpar2-moved-to-github.git diff --git a/www/demo/search.js b/www/demo/search.js index 41b19b5..636b6e6 100644 --- a/www/demo/search.js +++ b/www/demo/search.js @@ -1,4 +1,4 @@ -/* $Id: search.js,v 1.7 2007-01-08 11:13:07 sondberg Exp $ +/* $Id: search.js,v 1.13 2007-01-10 11:42:17 sondberg Exp $ * --------------------------------------------------- * Javascript container */ @@ -21,6 +21,7 @@ var session_cells = Array('query', 'startrec', 'action_type'); var old_session = session_read(); var url_surveillence; var recstoshow = 15; +var page_window = 5; // Number of pages prior to and after the current page var facet_list; var cur_facet = 0; @@ -72,8 +73,6 @@ function start_session() xinitSession.onreadystatechange=session_started; xinitSession.open("GET", url); xinitSession.send(null); - - //url_surveillence = setInterval(session_check, 200); } function ping_session() @@ -146,7 +145,55 @@ function update_action (new_action) { function make_pager (hits, offset, max) { - return '1 Next'; + var html = ''; + var off; + var start_offset = offset - page_window * max; + var div_elem = document.createElement('div'); + + div_elem.className = 'pages'; + + if (start_offset < 0) { + start_offset = 0; + } + + for (off = start_offset; + off < hits && off < (start_offset + 2 * page_window * max); + off += max) { + + var p = off / max + 1; + var page_elem = create_element('a', p); + var newline_node = document.createTextNode('\n'); + + if ((offset >= off) && (offset < (off + max))) { + page_elem.className = 'select'; + } + + page_elem.setAttribute('href', '#'); + page_elem.setAttribute('onclick', 'update_offset(' + off + ')'); + + div_elem.appendChild(page_elem); + div_elem.appendChild(newline_node); + } + + return div_elem; +} + + +function update_offset (offset) { + document.search.startrec.value = offset; + update_action('page'); + check_search(); + update_history(); + return false; +} + + +function create_element (name, cdata) { + var elem_node = document.createElement(name); + var text_node = document.createTextNode(cdata); + elem_node.appendChild(text_node); + + return elem_node; } @@ -158,6 +205,9 @@ function show_records() var xml = xshow.responseXML; var body = document.getElementById("body"); var hits = xml.getElementsByTagName("hit"); + + body.innerHTML = ''; + if (!hits[0]) // We should never get here with blocking operations { body.innerHTML = "No records yet"; @@ -171,46 +221,40 @@ function show_records() var start = Number(xml.getElementsByTagName('start')[0].childNodes[0].nodeValue); var num = Number(xml.getElementsByTagName('num')[0].childNodes[0].nodeValue); var clients = Number(xml.getElementsByTagName("activeclients")[0].childNodes[0].nodeValue); - body.innerHTML = '