From a60d941e42fc245d651cc66fa295eee770428502 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Fri, 9 Mar 2007 14:01:49 +0000 Subject: [PATCH] Further pz2.js updates. --- www/pz2_js/client_pz2.js | 33 ++++++++++++++++++++++++--------- www/pz2_js/index.html | 6 +++--- www/pz2_js/pz2.js | 18 +++++++++++++++++- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/www/pz2_js/client_pz2.js b/www/pz2_js/client_pz2.js index 1ba9389..aaa5bab 100644 --- a/www/pz2_js/client_pz2.js +++ b/www/pz2_js/client_pz2.js @@ -1,12 +1,25 @@ -function init() { - my_paz = new pz2( { "onshow": my_onshow, - "onstat": my_onstat, - "onterm": my_onterm, - "termlist": "subject,author", - "onbytarget": my_onbytarget, - "onrecord": my_onrecord } ); -} +// very simple client that shows a basic usage of the pz2.js + +// create a parameters array and pass it to the pz2's constructor +// then register the form submit event with the pz2.search function + +my_paz = new pz2( { "onshow": my_onshow, + "onstat": my_onstat, + "onterm": my_onterm, + "termlist": "subject,author", + "onbytarget": my_onbytarget, + "onrecord": my_onrecord } ); +// wait until the DOM is rady (could have been defined in the HTML) +$(document).ready( function() { document.search.onsubmit = onFormSubmitEventHandler; } ); + +function onFormSubmitEventHandler() { + my_paz.search(document.search.query.value, 15, 'relevance'); + return false; +} +// +// pz2.js event handlers: +// function my_onshow(data) { var body = document.getElementById("body"); body.innerHTML = ""; @@ -48,11 +61,13 @@ function my_onterm(data) { } function my_onrecord(data) { + details = data; recordDiv = document.getElementById(data.recid); recordDiv.innerHTML = "
Ttle : " + data["md-title"] + "
Date : " + data["md-date"] + "
Author : " + data["md-author"] + - "
Subject : " + data["md-subject"] + "
"; + "Subject : " + data["md-subject"] + + "Location : " + data["location"][0].name + ""; } diff --git a/www/pz2_js/index.html b/www/pz2_js/index.html index 46108c8..5f90366 100644 --- a/www/pz2_js/index.html +++ b/www/pz2_js/index.html @@ -1,16 +1,16 @@ + - - +
pz2.js test -
+ Search: diff --git a/www/pz2_js/pz2.js b/www/pz2_js/pz2.js index e8924b0..5725858 100644 --- a/www/pz2_js/pz2.js +++ b/www/pz2_js/pz2.js @@ -254,7 +254,23 @@ pz2.prototype = { if ( recordNode.childNodes[i].nodeType == Node.ELEMENT_NODE ) { var nodeName = recordNode.childNodes[i].nodeName; var nodeText = recordNode.childNodes[i].firstChild.nodeValue; - record[nodeName] = nodeText; + record[nodeName] = nodeText; + } + } + // the location is hard coded + var locationNodes = recordNode.getElementsByTagName("location"); + record["location"] = new Array(); + for ( i = 0; i < locationNodes.length; i++ ) { + record["location"][i] = { + "id": locationNodes[i].getAttribute("id"), + "name": locationNodes[i].getAttribute("name") + }; + for ( j = 0; j < locationNodes[i].childNodes.length; j++) { + if ( locationNodes[i].childNodes[j].nodeType == Node.ELEMENT_NODE ) { + var nodeName = locationNodes[i].childNodes[j].nodeName; + var nodeText = locationNodes[i].childNodes[j].firstChild.nodeValue; + record["location"][i][nodeName] = nodeText; + } } } __myself.recordCallback(record); -- 1.7.10.4