var mkdru = {
// Settings to pass to pz2.js
useSessions: Drupal.settings.mkdru.use_sessions === '1',
- // showResponseType: 'json',
// Variables
active: false,
pz2: null,
},
subject: {
pz2Name: 'subject',
- max: Drupal.settings.mkdru.subject_max
+ max: Drupal.settings.mkdru.subject_max,
+ multiLimit: true,
+ limiter: 'su'
},
author: {
pz2Name: 'author',
- max: Drupal.settings.mkdru.author_max
+ max: Drupal.settings.mkdru.author_max,
+ multiLimit: false,
+ limiter: 'au'
}
},
// State
}
};
+// return link to limit facet
+mkdru.addLimit = function (facet, limit) {
+ var newHash = $.deparam.fragment();
+ delete newHash['page'];
+ if ((typeof(newHash['limit_' + facet]) === 'undefined')
+ || !mkdru.facets[facet].multiLimit) {
+ newHash['limit_' + facet] = limit;
+ }
+ else {
+ newHash['limit_' + facet] += ';' + limit;
+ }
+ return $.param.fragment("#", newHash);
+};
+// return link to remove limit from facet
+mkdru.removeLimit = function (facet, limit) {
+ var newHash = $.deparam.fragment();
+ delete newHash['page'];
+ if (!newHash['limit_' + facet].indexOf(';') || !mkdru.facets[facet].multiLimit) {
+ delete newHash['limit_' + facet];
+ }
+ else {
+ var limits = newHash['limit_' + facet].split(';');
+ for (var i = 0; i < limits.length; i++) {
+ if (limits[i] == limit) {
+ limits.splice(i, 1);
+ newHash['limit_' + facet] = limits.join(';');
+ break;
+ }
+ }
+ }
+ return $.param.fragment("#", newHash);
+};
-//form submit handler
+
+
+// form submit handler
mkdru.submitQuery = function () {
// new query, back to defaults (shallow copy)
mkdru.state = $.extend({}, mkdru.defaultState);
return false;
};
-//criteria drop-down (perpage, sort) handler
+// criteria drop-down (perpage, sort) handler
mkdru.submitCriteria = function () {
mkdru.pollDropDowns();
//search is not ON, do nothing
var query = mkdru.state.query;
// facet limit implementation
- if (mkdru.state.limit_source) {
- filter = 'pz:id=' + mkdru.state.limit_source;
- }
- if (mkdru.state.limit_subject) {
- query += ' and su="' + mkdru.state.limit_subject + '"';
- }
- if (mkdru.state.limit_author) {
- query += ' and au="' + mkdru.state.limit_author + '"';
+ for (var facet in mkdru.facets) {
+ // facet is limited
+ if (mkdru.state['limit_' + facet]) {
+ if (facet == "source") {
+ filter = 'pz:id=' + mkdru.state.limit_source;
+ }
+ else {
+ var limits = mkdru.state['limit_' + facet].split(';');
+ for (var i = 0; i < limits.length; i++) {
+ // ex. query + and au="{limit_author}"
+ query += ' and ' + mkdru.facets[facet]['limiter'] + '="'
+ + mkdru.state['limit_' + facet] + '"';
+ }
+ }
+ }
}
+
mkdru.pz2.search(query, mkdru.state.perpage, mkdru.state.sort, filter);
- //inform others that the search is ON
mkdru.active = true;
};
};
mkdru.generatePager = function () {
- // make sure page param is a number, otherwise pageing frwd will be broken
+ // cast page parameter to numeric so we can add to it
if (typeof mkdru.state.page == "string") {
mkdru.state.page = Number(mkdru.state.page);
}
var first = (mkdru.state.page - mkdru.pagerRange > 0)
? mkdru.state.page - mkdru.pagerRange : 1;
var last = first + 2 * mkdru.pagerRange < total
- ? first + 2 * mkdru.pagerRange : total;
+ ? first + 2 * mkdru.pagerRange : total;
var prev = null;
var next = null;
var pages = [];
if (typeof(Drupal.settings.mkdru.query) !== "undefined") {
mkdru.state.query = Drupal.settings.mkdru.query
}
-
+
//not running against SP? init, otherwise authenticate
if (mkdru.useSessions) {
mkdru.pz2.init();