// Set up namespace and some state.
var mkws = {};
-if (!mkws_config)
- var mkws_config = {}; // for the guys who forgot to define mkws_config...
-
-// Wrapper for jQuery
-(function ($) {
-
/*
* global config object: mkws_config
*
- * needs to be defined in the HTML header before
- * including this JS file
+ * Needs to be defined in the HTML header before including this JS file.
+ * Define empty mkws_config for simple applications that don't define it.
*/
+if (!mkws_config)
+ var mkws_config = {};
-if (typeof mkws_config.use_service_proxy === 'undefined')
- mkws_config.use_service_proxy = true;
-
-var pazpar2_url = mkws_config.pazpar2_url ? mkws_config.pazpar2_url : "http://mkws.indexdata.com/service-proxy/";
-
-mkws.pazpar2path = pazpar2_url;
-mkws.usesessions = mkws_config.use_service_proxy ? false : true;
+// Wrapper for jQuery
+(function ($) {
mkws.locale_lang = {
"de": {
"start": $.now(),
"last": $.now()
};
+
mkws.debug_function = function (string) {
if (!mkws.debug_level)
return;
}
var debug = mkws.debug_function; // local alias
+{
+ /* default mkws config */
+ var config_default = {
+ use_service_proxy: true,
+ service_proxy_auth: "http://mkws.indexdata.com/service-proxy-auth",
+ lang: "",
+ sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
+ perpage_options: [10, 20, 30, 50],
+ sort_default: "relevance",
+ perpage_default: 20,
+ query_width: 50,
+ show_lang: true, /* show/hide language menu */
+ show_sort: true, /* show/hide sort menu */
+ show_perpage: true, /* show/hide perpage menu */
+ lang_options: [], /* display languages links for given languages, [] for all */
+ facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */
+ responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
+ debug_level: 1, /* debug level for development: 0..2 */
+
+ dummy: "dummy"
+ };
+
+ /* set global debug_level flag early */
+ if (typeof mkws_config.debug_level !== 'undefined') {
+ mkws.debug_level = mkws_config.debug_level;
+ } else if (typeof config_default.debug_level !== 'undefined') {
+ mkws.debug_level = config_default.debug_level;
+ }
+
+ /* override standard config values by function parameters */
+ for (var k in config_default) {
+ if (typeof mkws_config[k] === 'undefined')
+ mkws_config[k] = config_default[k];
+ debug("Set config: " + k + ' => ' + mkws_config[k]);
+ }
+}
+
+if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
+ debug("Reset query width: " + mkws_config.query_width);
+ mkws_config.query_width = 50;
+}
+
for (var key in mkws_config) {
if (mkws_config.hasOwnProperty(key)) {
if (key.match(/^language_/)) {
var lang = key.replace(/^language_/, "");
// Copy custom languages into list
mkws.locale_lang[lang] = mkws_config[key];
+ debug("Added locally configured language '" + lang + "'");
}
}
}
// autoInit is set to true on default
var my_paz = new pz2( { "onshow": my_onshow,
"showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way
- "pazpar2path": mkws.pazpar2path,
+ "pazpar2path": mkws_config.pazpar2_url || "http://mkws.indexdata.com/service-proxy/",
"oninit": my_oninit,
"onstat": my_onstat,
"onterm": my_onterm,
"termlist": "xtargets,subject,author",
"onbytarget": my_onbytarget,
- "usesessions" : mkws.usesessions,
+ "usesessions" : mkws_config.use_service_proxy ? false : true,
"showResponseType": '', // or "json" (for debugging?)
"onrecord": my_onrecord } );
for (var i = 0; i < data.hits.length; i++) {
var hit = data.hits[i];
html.push('<div class="record" id="mkwsRecdiv_'+hit.recid+'" >'
- +'<span>'+ (i + 1 + recPerPage * (curPage - 1)) +'. </span>'
+'<a href="#" id="mkwsRec_'+hit.recid
+'" onclick="mkws.showDetails(this.id);return false;"><b>'
+ hit["md-title"] +' </b></a>');
stat.innerHTML = '<span class="head">Status info</span>' +
' -- ' +
- '<span class="clients">' + data.activeclients + '/' + data.clients + '</span>' +
+ '<span class="clients">Active clients: ' + data.activeclients + '/' + data.clients + '</span>' +
' -- ' +
- '<span class="records">' + data.records + '/' + data.hits + '</span>';
+ '<span class="records">Retrieved records: ' + data.records + '/' + data.hits + '</span>';
}
function my_onterm(data) {
* result pages.
*/
function mkws_html_all() {
-
- /* default mkws config */
- /* ### No defaults given for:
- * lang, service_proxy_auth, use_service_proxy
- * and of course the optional language_* entries.
- */
- var config_default = {
- sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
- perpage_options: [10, 20, 30, 50],
- sort_default: "relevance",
- perpage_default: 20,
- query_width: 50,
- show_lang: true, /* show/hide language menu */
- show_sort: true, /* show/hide sort menu */
- show_perpage: true, /* show/hide perpage menu */
- lang_options: [], /* display languages links for given languages, [] for all */
- facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */
- responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
- debug_level: 1, /* debug level for development: 0..2 */
-
- dummy: "dummy"
- };
-
- /* set global debug_level flag early */
- if (typeof mkws_config.debug_level !== 'undefined') {
- mkws.debug_level = mkws_config.debug_level;
- } else if (typeof config_default.debug_level !== 'undefined') {
- mkws.debug_level = config_default.debug_level;
- }
-
- /* override standard config values by function parameters */
- for (var k in config_default) {
- if (typeof mkws_config[k] === 'undefined')
- mkws_config[k] = config_default[k];
- debug("Set config: " + k + ' => ' + mkws_config[k]);
- }
-
- if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
- debug("Reset query width: " + mkws_config.query_width);
- mkws_config.query_width = 50;
- }
-
mkws_set_lang();
if (mkws_config.show_lang)
mkws_html_lang();
var ranking_data = '';
ranking_data += '<form name="mkwsSelect" id="mkwsSelect" action="" >';
if (mkws_config.show_sort) {
- ranking_data += M('Sort by') + ' ' + mkws_html_sort(mkws_config) + ' ';
+ ranking_data += M('Sort by') + ' ' + mkws_html_sort() + ' ';
}
if (mkws_config.show_perpage) {
- ranking_data += M('and show') + ' ' + mkws_html_perpage(mkws_config) + ' ' + M('per page') + '.';
+ ranking_data += M('and show') + ' ' + mkws_html_perpage() + ' ' + M('per page') + '.';
}
ranking_data += '</form>';
$("#mkwsRanking").html(ranking_data);
}
- mkws_html_switch(mkws_config);
+ mkws_html_switch();
if (mkws_config.use_service_proxy)
mkws_service_proxy_auth(mkws_config.service_proxy_auth);
}
function mkws_set_lang() {
- var lang = $.parseQuerystring().lang || mkws_config.lang || "";
+ var lang = $.parseQuerystring().lang || mkws_config.lang;
if (!lang || !mkws.locale_lang[lang]) {
mkws_config.lang = ""
} else {
return mkws_config.lang;
}
-function mkws_html_switch(config) {
+function mkws_html_switch() {
debug("HTML switch");
$("#mkwsSwitch").append($('<a href="#" id="mkwsSwitch_records" onclick="mkws.switchView(\'records\')">' + M('Records') + '</a>'));
$("#mkwsTargets").css("display", "none");
}
-function mkws_html_sort(config) {
+function mkws_html_sort() {
debug("HTML sort");
var sort_html = '<select name="mkwsSort" id="mkwsSort">';
- for(var i = 0; i < config.sort_options.length; i++) {
- var key = config.sort_options[i][0];
- var val = config.sort_options[i].length == 1 ? config.sort_options[i][0] : config.sort_options[i][1];
+ for(var i = 0; i < mkws_config.sort_options.length; i++) {
+ var opt = mkws_config.sort_options[i];
+ var key = opt[0];
+ var val = opt.length == 1 ? opt[0] : opt[1];
sort_html += '<option value="' + key + '"';
- if (key == config.sort_default) {
+ if (key == mkws_config.sort_default) {
sort_html += ' selected="selected"';
}
- sort_html += '>' + val + '</option>';
+ sort_html += '>' + M(val) + '</option>';
}
sort_html += '</select>';
return sort_html;
}
-function mkws_html_perpage(config) {
+function mkws_html_perpage() {
debug("HTML perpage");
var perpage_html = '<select name="mkwsPerpage" id="mkwsPerpage">';
- for(var i = 0; i < config.perpage_options.length; i++) {
- var key = config.perpage_options[i];
+ for(var i = 0; i < mkws_config.perpage_options.length; i++) {
+ var key = mkws_config.perpage_options[i];
perpage_html += '<option value="' + key + '"';
- if (key == config.perpage_default) {
+ if (key == mkws_config.perpage_default) {
perpage_html += ' selected="selected"';
}
perpage_html += '>' + key + '</option>';
* for the site.
*/
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, function(err) {
if (!lang || !mkws.locale_lang[lang])
return word;
- return mkws.locale_lang[lang][word] ? mkws.locale_lang[lang][word] : word;
+ return mkws.locale_lang[lang][word] || word;
}
/*