X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=www%2Fjsdemo%2Fexample_client.js;h=fd9c37ee8eded2de4dadbbff82324efe729656ad;hb=ba822e059b00112dd4f4c691213270334ded760c;hp=2b1046585567d403e63197204d9a91ad03d41101;hpb=e0fd929c14a4b675290d3179239a5e6a45e55418;p=pazpar2-moved-to-github.git
diff --git a/www/jsdemo/example_client.js b/www/jsdemo/example_client.js
index 2b10465..fd9c37e 100644
--- a/www/jsdemo/example_client.js
+++ b/www/jsdemo/example_client.js
@@ -1,5 +1,4 @@
/* A very simple client that shows a basic usage of the pz2.js
-** $Id: example_client.js,v 1.6 2008-01-15 13:59:18 jakub Exp $
*/
// create a parameters array and pass it to the pz2's constructor
@@ -7,9 +6,11 @@
// autoInit is set to true on default
var usesessions = true;
var pazpar2path = '/pazpar2/search.pz2';
-if (document.location.hash == '#nosessions') {
+var showResponseType = '';
+if (document.location.hash == '#useproxy') {
usesessions = false;
- pazpar2path = '/pazpar2-proxy/';
+ pazpar2path = '/service-proxy/';
+ showResponseType = 'json';
}
my_paz = new pz2( { "onshow": my_onshow,
@@ -21,6 +22,7 @@ my_paz = new pz2( { "onshow": my_onshow,
"termlist": "xtargets,subject,author",
"onbytarget": my_onbytarget,
"usesessions" : usesessions,
+ "showResponseType": showResponseType,
"onrecord": my_onrecord } );
// some state vars
var curPage = 1;
@@ -55,27 +57,27 @@ function my_onshow(data) {
drawPager(pager);
// navi
var results = document.getElementById("results");
- results.innerHTML = "";
-
+
+ var html = [];
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
- var html = '
'
+ html.push('
'
+'
'+ (i + 1 + recPerPage * (curPage - 1)) +'. '
+'
'
- + hit["md-title"] +' ';
- if (hit["md-title-remainder"] !== undefined) {
- html += '
' + hit["md-title-remainder"] + ' ';
- }
- if (hit["md-title-responsibility"] !== undefined) {
- html += '
'+ hit["md-title-responsibility"] +'';
- }
- html += '
';
- results.innerHTML += html;
+ + hit["md-title"] +' ');
+ if (hit["md-title-remainder"] !== undefined) {
+ html.push('
' + hit["md-title-remainder"] + ' ');
+ }
+ if (hit["md-title-responsibility"] !== undefined) {
+ html.push('
'+hit["md-title-responsibility"]+'');
+ }
if (hit.recid == curDetRecId) {
- drawCurDetails();
+ html.push(renderDetails(curDetRecData));
}
+ html.push('
');
}
+ replaceHtml(results, html.join(''));
}
function my_onstat(data) {
@@ -91,51 +93,42 @@ function my_onstat(data) {
}
function my_onterm(data) {
- var termlist = document.getElementById("termlist");
- termlist.innerHTML = "
TERMLISTS:
";
-
- termlist.innerHTML += '.::Sources
';
+ var termlists = [];
+ termlists.push('
TERMLISTS:
.::Sources
');
for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) {
- termlist.innerHTML += ''
- + data.xtargets[i].name
- + ' ('
- + data.xtargets[i].freq
- + ')
';
+ termlists.push('' + data.xtargets[i].name
+ + ' (' + data.xtargets[i].freq + ')
');
}
-
- termlist.innerHTML += "
";
-
- termlist.innerHTML += '.::Subjects
';
+
+ termlists.push('
.::Subjects
');
for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) {
- termlist.innerHTML += ''
- + data.subject[i].name
- + ' ('
- + data.subject[i].freq
- + ')
';
+ termlists.push('' + data.subject[i].name + ' ('
+ + data.subject[i].freq + ')
');
}
-
- termlist.innerHTML += "
";
-
- termlist.innerHTML += '.::Authors
';
+
+ termlists.push('
.::Authors
');
for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) {
- termlist.innerHTML += ''
+ termlists.push(''
+ data.author[i].name
+ ' ('
+ data.author[i].freq
- + ')
';
+ + ')
');
}
-
+ var termlist = document.getElementById("termlist");
+ replaceHtml(termlist, termlists.join(''));
}
function my_onrecord(data) {
+ // FIXME: record is async!!
+ clearTimeout(my_paz.recordTimer);
// in case on_show was faster to redraw element
var detRecordDiv = document.getElementById('det_'+data.recid);
- if ( detRecordDiv )
- return;
+ if (detRecordDiv) return;
curDetRecData = data;
- drawCurDetails();
+ var recordDiv = document.getElementById('recdiv_'+curDetRecData.recid);
+ var html = renderDetails(curDetRecData);
+ recordDiv.innerHTML += html;
}
function my_onbytarget(data) {
@@ -324,40 +317,54 @@ function switchView(view) {
}
// detailed record drawing
-function showDetails ( prefixRecId ) {
+function showDetails (prefixRecId) {
var recId = prefixRecId.replace('rec_', '');
+ var oldRecId = curDetRecId;
+ curDetRecId = recId;
// remove current detailed view if any
- var detRecordDiv = document.getElementById('det_'+curDetRecId);
+ var detRecordDiv = document.getElementById('det_'+oldRecId);
// lovin DOM!
- if ( detRecordDiv )
- detRecordDiv.parentNode.removeChild(detRecordDiv);
+ if (detRecordDiv)
+ detRecordDiv.parentNode.removeChild(detRecordDiv);
- // if the same clicked do not redraw
- if ( recId == curDetRecId ) {
+ // if the same clicked, just hide
+ if (recId == oldRecId) {
curDetRecId = '';
+ curDetRecData = null;
return;
}
-
- curDetRecId = recId;
// request the record
my_paz.record(recId);
}
-function drawCurDetails ()
+function replaceHtml(el, html) {
+ var oldEl = typeof el === "string" ? document.getElementById(el) : el;
+ /*@cc_on // Pure innerHTML is slightly faster in IE
+ oldEl.innerHTML = html;
+ return oldEl;
+ @*/
+ var newEl = oldEl.cloneNode(false);
+ newEl.innerHTML = html;
+ oldEl.parentNode.replaceChild(newEl, oldEl);
+ /* Since we just removed the old element from the DOM, return a reference
+ to the new element, which can be used to restore variable references. */
+ return newEl;
+};
+
+function renderDetails(data, marker)
{
- var data = curDetRecData;
- var recordDiv = document.getElementById('recdiv_'+data.recid);
- var details = "";
+ var details = '';
+ if (marker) details += ''+ marker + ' |
';
if (data["md-title"] != undefined) {
details += 'Title | : '+data["md-title"];
- if (data["md-title-remainder"] !== undefined) {
- details += ' : ' + data["md-title-remainder"] + ' ';
- }
- if (data["md-title-responsibility"] !== undefined) {
- details += ' '+ data["md-title-responsibility"] +'';
- }
- details += ' |
';
+ if (data["md-title-remainder"] !== undefined) {
+ details += ' : ' + data["md-title-remainder"] + ' ';
+ }
+ if (data["md-title-responsibility"] !== undefined) {
+ details += ' '+ data["md-title-responsibility"] +'';
+ }
+ details += '';
}
if (data["md-date"] != undefined)
details += 'Date | : ' + data["md-date"] + ' |
';
@@ -369,6 +376,7 @@ function drawCurDetails ()
details += 'Subject | : ' + data["location"][0]["md-subject"] + ' |
';
if (data["location"][0]["@name"] != undefined)
details += 'Location | : ' + data["location"][0]["@name"] + " (" +data["location"][0]["@id"] + ")" + ' |
';
- recordDiv.innerHTML += '';
+ details += '
';
+ return details;
}
//EOF