limiter: 'au'
}
},
- // State
+ // State; Keys limit_{facet key} will also be initialised
defaultState: {
page: 1,
perpage: 20,
sort: 'relevance',
- filter: null,
query:'',
recid:null
},
};
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();
}