X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2FMETA-INF%2Fresources%2Fpz2utils%2Flisteners.js;h=b46014e7e4a3e1888e84220169d3d97b3b178640;hb=f969f221326787617bd4a8766bed1942d010eae0;hp=73e592b6327c672d4b6b8a6e999464c31fd414dc;hpb=bb19150e6ad6f7f34a31d8ac6e3e52c104839dcb;p=mkjsf-moved-to-github.git diff --git a/src/META-INF/resources/pz2utils/listeners.js b/src/META-INF/resources/pz2utils/listeners.js index 73e592b..b46014e 100644 --- a/src/META-INF/resources/pz2utils/listeners.js +++ b/src/META-INF/resources/pz2utils/listeners.js @@ -46,24 +46,35 @@ function renderOnRecordTargets(doRefresh) { } } -// Listens for browser initiated changes to 'window.location.hash' and sends the -// hash -// changes to the back-end (to have the back-end pull up a previous Pazpar2 -// state) +// Listens for browser initiated changes to 'window.location.hash' and sends +// the hash key changes to the back-end, to have the back-end pull up a previous +// Pazpar2 state. +// +// See also: The field in pz2watch.xhtml, the StateListener function below, +// the method Pz2Bean.handleQueryStateChanges(), and the classes +// Pazpar2State and StateManager for a complete picture of browser history +// handling. function windowlocationhashListener() { if (trackHistory) { - // console.log("browser hash update detected"); + var stateKey = document.getElementById("pz2watch:windowlocationhash"); - if (window.location.hash != stateKey.value) { - // console.log("updating stateKey with new browser hash: " + - // window.location.hash); - stateKey.value = window.location.hash; - if (!stateKey.value) - window.location.hash = '#1'; - stateKey.onchange(); + // console.log("browser hash update response detected."); + // console.log("pz2watch:windowlocationhash: [" + stateKey.value + "]"); + // console.log("window.location.hash: [" + window.location.hash + "]"); + if (window.location.hash != stateKey.value) { + if (window.location.hash) { + //console.log("updating pz2watch:windowlocationhash with new window.location.hash [" + window.location.hash + "]"); + stateKey.value = window.location.hash; + //console.log("firing pz2watch:windowlocationhash onChange"); + stateKey.onchange(); + } else if (stateKey.value) { + //console.log("updating window.location.hash with pz2watch:windowlocationhash [" + stateKey.value + "]"); + window.location.hash = stateKey.value; + //console.log("firing pz2watch:windowlocationhash onChange"); + stateKey.onchange(); + } } else { - // console.log("State hash already has the value of the new browser hash - - // not updating state hash"); + //console.log("State hash already has the value of the new browser hash - not updating state hash"); } } } @@ -93,17 +104,17 @@ function errorListener(data) { if (data.source.name === "pz2watch:activeclientsField") { alert("This occurred when polling: [" + data.description - + "]. The page could be in an inconsistent state after this. We apologize for the inconvenience."); + + "]."); } else { var pattern = /viewId.*could not be restored./; if (pattern.test(data.description)) { // ignore - caught by view expiration listener } else { alert("An error [" - + data.description + + data.errorName + ": " +data.description + "] was triggered by [" + data.source.name - + "]. The page could be in an inconsistent state after this. We apologize for the inconvenience."); + + "]."); } } } @@ -139,14 +150,12 @@ var StateListener = function() { this.invoke = function(field) { var stateKeyDoc = StringtoXML(field.textContent || field.text); var stateKeyValue = stateKeyDoc.childNodes[0].getAttribute("value"); - // console.log('Application hash update detected. New value: ' + - // stateKeyValue); + // console.log('Received state key update from the back-end: ' + stateKeyValue); if (stateKeyValue !== window.location.hash) { window.location.hash = stateKeyValue; - // console.log("Browsers hash updated accordingly."); + // console.log("Browsers hash (window.location.hash) updated with [" + stateKeyValue + "]"); } else { - // console.log("Browsers hash already has the value of the state hash. Not - // updating browser hash."); + // console.log("Browsers hash (window.location.hash) already has the value [" + stateKeyValue + "]"); } }; }; @@ -173,13 +182,12 @@ var ActiveclientsRecordListener = function() { this.invoke = function(field) { var updateDoc = StringtoXML(field.textContent || field.text); var activeClientsRecordValue = (updateDoc.childNodes[0].textContent || updateDoc.childNodes[0].text); - console.log('Activeclients response for record detected: ' - + activeClientsRecordValue); + // console.log('Activeclients response for record detected: ' + activeClientsRecordValue); clearTimeout(renderOnRecordTargetsReqVar); if (activeClientsRecordValue > '0') { renderOnRecordTargets(true); } else { - console.log('Active clients is 0, final rendering'); + // console.log('Active clients is 0, final rendering'); renderOnRecordTargets(false); } };