-
- var termlists = [];
- termlists.push('<div class="title">' + M('Termlists') + '</div>');
-
- termlists.push('<div class="facet">');
- termlists.push('<div class="termtitle">' + M('Sources') + '</div>');
- for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) {
- termlists.push('<a href="#" target_id='+data.xtargets[i].id + ' onclick="limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue);return false;">'
- + data.xtargets[i].name
- + ' </a><span> ('
- + data.xtargets[i].freq
- + ')</span><br/>');
- }
- termlists.push('</div>');
-
- termlists.push('<div class="facet">');
- termlists.push('<div class="termtitle">' + M('Subjects') + '</div>');
- for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) {
- termlists.push('<a href="#" onclick="limitQuery(\'su\', this.firstChild.nodeValue);return false;">'
- + data.subject[i].name
- + '</a><span> ('
- + data.subject[i].freq
- + ')</span><br/>');
- }
- termlists.push('</div>');
-
- termlists.push('<div class="facet">');
- termlists.push('<div class="termtitle">' + M('Authors') + '</div>');
- for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) {
- termlists.push('<a href="#" onclick="limitQuery(\'au\', this.firstChild.nodeValue);return false;">'
- + data.author[i].name
- + ' </a><span> ('
- + data.author[i].freq
- + ')</span><br/>');
- }
- termlists.push('</div>');
-
- var termlist = document.getElementById("termlist");
- replaceHtml(termlist, termlists.join(''));
+ }
+
+ // display if we first got results
+ $("#mkwsTermlists").show();
+
+ var acc = [];
+ acc.push('<div class="title">' + M('Termlists') + '</div>');
+ var facets = mkws_config.facets;
+
+ for(var i = 0; i < facets.length; i++) {
+ if (facets[i] == "sources") {
+ add_single_facet(acc, "Sources", data.xtargets, SourceMax, null);
+ } else if (facets[i] == "subjects") {
+ add_single_facet(acc, "Subjects", data.subject, SubjectMax, "su");
+ } else if (facets[i] == "authors") {
+ add_single_facet(acc, "Authors", data.author, AuthorMax, "au");
+ } else {
+ alert("bad facet configuration: '" + facets[i] + "'");
+ }
+ }
+
+ var termlist = document.getElementById("mkwsTermlists");
+ replaceHtml(termlist, acc.join(''));
+
+ if (mkws_config.responsive_design)
+ mkws_mobile_resize();
+}
+
+function add_single_facet(acc, caption, data, max, cclIndex) {
+ acc.push('<div class="facet">');
+ acc.push('<div class="termtitle">' + M(caption) + '</div>');
+ for (var i = 0; i < data.length && i < max; i++ ) {
+ acc.push('<a href="#" ');
+ var action;
+ if (!cclIndex) {
+ // Special case: target selection
+ acc.push('target_id='+data[i].id+' ');
+ action = 'limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
+ } else {
+ action = 'limitQuery(\'' + cclIndex + '\', this.firstChild.nodeValue)';
+ }
+ acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
+ + '<span> (' + data[i].freq + ')</span><br/>');
+ }
+ acc.push('</div>');