From: Jason Skomorowski Date: Thu, 3 Mar 2011 06:29:06 +0000 (+0100) Subject: Fix mkdru.hashChange() to call pz2.search() when appropriate X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=a614f93e60ac470e1da4fd52ede57a702e48d13b;p=mkdru-moved-to-drupal.org.git Fix mkdru.hashChange() to call pz2.search() when appropriate --- diff --git a/mkdru.client.js b/mkdru.client.js index ce5637e..f6188ea 100644 --- a/mkdru.client.js +++ b/mkdru.client.js @@ -34,12 +34,11 @@ var mkdru = { limiter: 'au' } }, - // State + // State; Keys limit_{facet key} will also be initialised defaultState: { page: 1, perpage: 20, sort: 'relevance', - filter: null, query:'', recid:null }, @@ -228,21 +227,28 @@ mkdru.uiFromState = function () { }; mkdru.hashChange = function () { + // do we need to restart the search? + var searchTrigger = false; + // shallow copy of state so we can see what changed. + var oldState = $.extend({}, mkdru.state); mkdru.stateFromHash(); - // Request for details - if (mkdru.state.recid) { + // only have to compare values since all keys are initialised + for (key in mkdru.state) { + var changed = (mkdru.state[key] != oldState[key]); + if (key.substring(0,5) === 'limit' && changed) + searchTrigger = true; + if (key === 'page' && changed) + mkdru.pz2.showPage(mkdru.state.page-1); + if (key === 'query' && changed) + searchTrigger = true; + } + if (searchTrigger) + mkdru.search(); + // request for record detail + if (mkdru.state.recid && (mkdru.state.recid != oldState.recid)) { mkdru.pz2.record(mkdru.state.recid); } - // Other internal link else { - // may need to run search again to limit targets - for (key in mkdru.state) { - if (key.substring(0,5) === 'limit' && mkdru.state[key]) { - mkdru.search(); - break; - } - } - mkdru.pz2.showPage(mkdru.state.page-1); $('.mkdru-detail').hide(); $('.mkdru-results').show(); }