From: Jakub Skoczen Date: Fri, 9 Mar 2007 16:06:42 +0000 (+0000) Subject: Cosmetic: timeouts can be specified as parameters, parameters moved to a single array. X-Git-Tag: stable.27032007~19 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=3c658db277708a717349cfb2603f4186be56beee;p=pazpar2-moved-to-github.git Cosmetic: timeouts can be specified as parameters, parameters moved to a single array. --- diff --git a/www/pz2_js/client_pz2.js b/www/pz2_js/client_pz2.js index aaa5bab..c759e6f 100644 --- a/www/pz2_js/client_pz2.js +++ b/www/pz2_js/client_pz2.js @@ -4,14 +4,19 @@ // then register the form submit event with the pz2.search function my_paz = new pz2( { "onshow": my_onshow, + "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way "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; } ); +// wait until the DOM is ready (could have been defined in the HTML) +$(document).ready( function() { + document.search.onsubmit = onFormSubmitEventHandler; + document.getElementById("next").onclick = pagerNext; + document.getElementById("prev").onclick = pagerPrev; + } ); function onFormSubmitEventHandler() { my_paz.search(document.search.query.value, 15, 'relevance'); @@ -83,3 +88,11 @@ function my_onbytarget(data) { "" + data[i].state + ""; } } + +function pagerNext() { + my_paz.showNext(); +} + +function pagerPrev() { + my_paz.showPrev(); +} diff --git a/www/pz2_js/index.html b/www/pz2_js/index.html index 5f90366..744eb0d 100644 --- a/www/pz2_js/index.html +++ b/www/pz2_js/index.html @@ -19,7 +19,7 @@ TERMLISTS:
- RESULTS:
+ Prev | Next
  diff --git a/www/pz2_js/pz2.js b/www/pz2_js/pz2.js index 5725858..e6c95d2 100644 --- a/www/pz2_js/pz2.js +++ b/www/pz2_js/pz2.js @@ -1,24 +1,27 @@ -/* prevent execution of more than once */ +// check for jQuery +if(typeof window.jQuery == "undefined") + throw new Error("pz2.js requires jQuery library"); +// prevent execution of more than once if(typeof window.pz2 == "undefined") { window.undefined = window.undefined; -var pz2 = function(callbackArr, autoInit, keepAlive) { +var pz2 = function(paramArray) { //for convenience __myself = this; // at least one callback required - if ( !callbackArr ) - throw new Error("Callback parameters array has to be suplied when instantiating a class"); + if ( !paramArray ) + throw new Error("An array with parameters has to be suplied when instantiating a class"); // function callbacks - __myself.statCallback = callbackArr.onstat || null; - __myself.showCallback = callbackArr.onshow || null; - __myself.termlistCallback = callbackArr.onterm || null; - __myself.recordCallback = callbackArr.onrecord || null; - __myself.bytargetCallback = callbackArr.onbytarget || null; + __myself.statCallback = paramArray.onstat || null; + __myself.showCallback = paramArray.onshow || null; + __myself.termlistCallback = paramArray.onterm || null; + __myself.recordCallback = paramArray.onrecord || null; + __myself.bytargetCallback = paramArray.onbytarget || null; // termlist keys - __myself.termKeys = callbackArr.termlist || "subject"; + __myself.termKeys = paramArray.termlist || "subject"; // some configurational stuff __myself.pz2String = "search.pz2"; @@ -29,8 +32,8 @@ var pz2 = function(callbackArr, autoInit, keepAlive) { __myself.pingStatusOK = false; __myself.searchStatusOK = false; - if ( keepAlive < __myself.keepAlive ) - __myself.keepAlive = keepAlive; + if ( paramArray.keepAlive < __myself.keepAlive ) + __myself.keepAlive = paramArray.keepAlive; // for sorting __myself.currentSort = "relevance"; @@ -44,13 +47,13 @@ var pz2 = function(callbackArr, autoInit, keepAlive) { __myself.currQuery = null; //timers - __myself.statTime = 2000; + __myself.statTime = paramArray.stattime || 2000; __myself.statTimer = null; - __myself.termTime = 1000; + __myself.termTime = paramArray.termtime || 1000; __myself.termTimer = null; - __myself.showTime = 1000; + __myself.showTime = paramArray.showtime || 1000; __myself.showTimer = null; - __myself.bytargetTime = 1000; + __myself.bytargetTime = paramArray.bytargettime || 1000; __myself.bytargetTimer = null; // active clients, updated by stat and show @@ -65,7 +68,7 @@ var pz2 = function(callbackArr, autoInit, keepAlive) { }); // auto init session? - if (autoInit !== false) + if (paramArray.autoInit !== false) __myself.init(__myself.keepAlive); } pz2.prototype = { @@ -354,6 +357,20 @@ pz2.prototype = { __myself.bytargetTimer = setTimeout("__myself.bytarget()", __myself.bytargetTime / 4); } ); + }, + // just for testing, probably shouldn't be here + showNext: function(page) + { + var step = page || 1; + __myself.show( ( step * __myself.currentNum ) + __myself.currentStart ); + }, + showPrev: function(page) + { + if (__myself.currentStart == 0 ) + return false; + var step = page || 1; + var newStart = __myself.currentStart - (step * __myself.currentNum ); + __myself.show( newStart > 0 ? newStart : 0 ); } }; }