"use strict"; // HTML5: disable for debug >= 2
-/*
- * global config object: mkws_config
- *
- * needs to be defined in the HTML header before
+/*
+ * global config object: mkws_config
+ *
+ * needs to be defined in the HTML header before
* including this JS file
*/
}
function my_onterm(data) {
- if (!mkws_config.termlist_menu)
+ // no facets
+ if (!mkws_config.facets || mkws_config.facets.length == 0) {
+ $("#termlist").parent().hide();
return;
-
+ }
+
+ // display if we first got results
+ $("#termlist").parent().show();
+
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/>');
+ var facets = mkws_config.facets;
+
+ for(var i = 0; i < facets.length; i++) {
+ if (facets[i] == "sources")
+ add_single_facet(termlists, "Sources", data.xtargets, SourceMax, null);
+ if (facets[i] == "subjects")
+ add_single_facet(termlists, "Subjects", data.subject, SubjectMax, "su");
+ if (facets[i] == "authors")
+ add_single_facet(termlists, "Authors", data.author, AuthorMax, "au");
}
- 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(''));
}
+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>');
+}
+
function my_onrecord(data) {
// FIXME: record is async!!
clearTimeout(my_paz.recordTimer);
switch_menu: true, /* show/hide Records|Targets menu */
lang_menu: true, /* show/hide language menu */
lang_display: [], /* display languages links for given languages, [] for all */
- termlist_menu: true, /* show/hide termlist */
+ facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */
+
debug: 0, /* debug level for development: 0..2 */
dummy: "dummy"
} else if (mkws_config_default.debug !== 'undefined') {
mkws_debug = mkws_config_default.debug;
}
-
+
/* override standard config values by function parameters */
for (var k in mkws_config_default) {
if (typeof config[k] === 'undefined')
debug("Reset query width: " + mkws_config.query_width);
mkws_config.query_width = 50;
}
-
- mkws_set_lang(mkws_config);
+
+ mkws_set_lang(mkws_config);
if (mkws_config.lang_menu)
- mkws_html_lang(mkws_config);
+ mkws_html_lang(mkws_config);
// For some reason, doing this programmatically results in
// document.search.query being undefined, hence the raw HTML.
mkws_service_proxy_auth(config.service_proxy_auth);
domReady();
+
+ // on first page, hide the termlist
+ $(document).ready(function() { $("#termlist").parent().hide(); } );
}
function mkws_set_lang(mkws_config) {
} else {
mkws_config.lang = lang;
}
-
+
debug("Locale language: " + (mkws_config.lang ? mkws_config.lang : "none"));
return mkws_config.lang;
}
function mkws_html_switch(config) {
debug("HTML switch");
-
+
$("#mkwsSwitch").html($("<a/>", {
href: '#',
onclick: "switchView(\'records\')",
function mkws_service_proxy_auth(auth_url) {
if (!auth_url)
auth_url = "http://mkws.indexdata.com/service-proxy-auth";
-
+
debug("Run service proxy auth URL: " + auth_url);
var request = new pzHttpRequest(auth_url);
for (var i = 0; i < lang_display.length; i++) {
hash[lang_display[i]] = 1;
}
-
+
for (var k in mkws_locale_lang) {
if (hash[k] == 1 || lang_display.length == 0)
list.push(k);
debug("Language menu for: " + list.join(", "));
/* the HTML part */
- var data = "";
+ var data = "";
for(var i = 0; i < list.length; i++) {
var l = list[i];
-
+
if (data)
data += ' | ';
-
+
if (lang == l) {
data += ' <span>' + l + '</span> ';
} else {
data += ' <a href="?lang=' + l + '">' + l + '</a> '
}
}
-
+
$("#mkwsLang").html(data);
}
nvpair[pair[0]] = pair[1];
});
return nvpair;
- },
+ },
pazpar2: function(data) {
document.write('<div id="mkwsSwitch"></div>\
<div id="mkwsLang"></div>\