$('.mkdru-status').html(Drupal.theme('mkdruStatus', data.activeclients, data.clients));
};
+mkdru.contains = function (hash, key, value) {
+ if (hash[key]) {
+ if (hash[key].length) {
+ for (var i=0; i<hash[key].length; i++) {
+ if (hash[key][i] === value) {
+ return true;
+ }
+ }
+ } else {
+ return hash[key] === value;
+ }
+ }
+ return false;
+}
+
mkdru.pz2Term = function (data) {
// if signaled, prepare container client-side
if (mkdru.facetContainerSelector) {
$(mkdru.facetContainerSelector).html(Drupal.theme('mkdruFacetContainer',
data, mkdru.facets));
}
+ // map all facets against selected, for simple rendering
+ var hash = $.deparam.fragment();
+ for (var key in hash) {
+ if (key.indexOf('limit') == 0 && hash[key].indexOf(';'))
+ hash[key.substr(6)] = hash[key].split(';');
+ delete hash[key];
+ }
for (var facet in mkdru.facets) {
- // facet is limited
- if (mkdru.state['limit_' + facet]) {
- $('.mkdru-facet-' + facet).html(Drupal.theme('mkdruFacetLimit',
- data[mkdru.facets[facet].pz2Name][0],
- mkdru.hashAddDelOne(null, null, 'limit_' + facet)));
- } else {
- $('.mkdru-facet-' + facet).html(Drupal.theme('mkdruFacet',
- data[mkdru.facets[facet].pz2Name],
- facet, mkdru.facets[facet].max));
+ var terms = data[mkdru.facets[facet].pz2Name];
+ for (var i=0; i<terms.length; i++) {
+ var term = terms[i];
+ var value = facet == "source" ? term.id : term.name;
+ if (mkdru.contains(hash, facet, value)) { //enabled
+ term.hashQuery = mkdru.removeLimit(facet, value);
+ term.selected = true;
+ } else { //disabled
+ term.hashQuery = mkdru.addLimit(facet, value);
+ term.selected = false;
+ }
}
+ $('.mkdru-facet-' + facet).html(
+ Drupal.theme('mkdruFacet', terms, facet, mkdru.facets[facet].max));
}
};
Drupal.theme.prototype.mkdruFacet = function (terms, facet, max) {
var html = "";
for (var i = 0; i < terms.length && i < max; i++ ) {
- html += '<a href="';
- if (facet == 'source')
- html += mkdru.addLimit(facet, terms[i].id);
- else
- html += mkdru.addLimit(facet, terms[i].name);
- html += '">' + terms[i].name + '</a><span> (' + terms[i].freq + ')</span><br/>';
- }
- return html;
-};
+ var term = terms[i];
+ html += '<a href="'+term.hashQuery+'"';
+ if (term.selected) html += ' class="cross"><strong';
+ html += '>'+terms[i].name;
+ if (term.selected) html += "</strong>";
+ html += '</a><span> (' + terms[i].freq
+ + ')</span><br/>';
-Drupal.theme.prototype.mkdruFacetLimit = function (term, link) {
- if (term) {
- return '<p>' + Drupal.t('Only displaying ') + term.name + '</p>'
- + '<p><a href="' + link + '">' + Drupal.t('Show all...') + '</a></p>';
}
+ return html;
};
Drupal.theme.prototype.mkdruFacetContainer = function (facets, facetCfg) {