X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=2896c44d5b7c926a20a40015ff964eafbb3813df;hb=0071d64575e2c1850fd18d536d504cf40fcd1e4a;hp=6c014f8559af80b8eebadcc7cbd413edf80d2b35;hpb=70bfae57902896a69e8bf4b4261574c555afcf46;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 6c014f8..2896c44 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -1,4 +1,7 @@
-/*! MKWS, the MasterKey Widget Set. Copyright (C) 2013-2014, Index Data */
+/*! MKWS, the MasterKey Widget Set.
+ * Copyright (C) 2013-2014 Index Data
+ * See the file LICENSE for details
+ */
"use strict"; // HTML5: disable for debug_level >= 2
@@ -225,8 +228,8 @@ function team($, teamName) {
"pazpar2path": mkws_config.pazpar2_url,
"oninit": my_oninit,
"onstat": my_onstat,
- "onterm": my_onterm,
- "termlist": "xtargets,subject,author",
+ "onterm": (mkws_config.facets.length ? my_onterm : undefined),
+ "termlist": mkws_config.facets.join(','),
"onbytarget": my_onbytarget,
"usesessions" : mkws_config.use_service_proxy ? false : true,
"showResponseType": '', // or "json" (for debugging?)
@@ -271,7 +274,8 @@ function team($, teamName) {
renderSummary(hit),
'');
if (hit.recid == m_curDetRecId) {
- html.push(renderDetails(m_curDetRecData));
+ if (m_curDetRecData)
+ html.push(renderDetails(m_curDetRecData));
}
}
results.html(html.join(''));
@@ -289,48 +293,50 @@ function team($, teamName) {
function my_onstat(data, teamName) {
debug("stat for " + teamName);
- var stat = document.getElementById("mkwsStat");
- if (stat == null)
+ var stat = $('.mkwsStat.mkwsTeam_' + teamName);
+ if (stat.length === 0)
return;
- stat.innerHTML = '' + M('Status info') + '' +
+ stat.html('' + M('Status info') + '' +
' -- ' +
'' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '' +
' -- ' +
- '' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '';
+ '' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '');
}
function my_onterm(data, teamName) {
debug("term for " + teamName);
- // no facets
+ var node = $(".mkwsTermlists.mkwsTeam_" + teamName);
+ if (node.length == 0) return;
+
+ // no facets: this should never happen
if (!mkws_config.facets || mkws_config.facets.length == 0) {
- $("#mkwsTermlists").hide();
+ alert("my_onterm called even though we have no facets: " + $.toJSON(data));
+ node.hide();
return;
}
// display if we first got results
- $("#mkwsTermlists").show();
+ node.show();
var acc = [];
acc.push('
\
+ var node = $(".mkwsTargets.mkwsTeam_" + m_teamName);
+ node.html('\
+
\
No information available yet.\
');
- $("#mkwsTargets").css("display", "none");
+ node.css("display", "none");
}
@@ -1046,18 +1057,18 @@ function team($, teamName) {
/* display a list of configured languages, or all */
var lang_options = mkws_config.lang_options || [];
- var hash = {};
+ var toBeIncluded = {};
for (var i = 0; i < lang_options.length; i++) {
- hash[lang_options[i]] = 1;
+ toBeIncluded[lang_options[i]] = true;
}
for (var k in mkws.locale_lang) {
- if (hash[k] == 1 || lang_options.length == 0)
+ if (toBeIncluded[k] || lang_options.length == 0)
list.push(k);
}
// add english link
- if (lang_options.length == 0 || hash[lang_default] == 1)
+ if (lang_options.length == 0 || toBeIncluded[lang_default])
list.push(lang_default);
debug("Language menu for: " + list.join(", "));
@@ -1077,38 +1088,10 @@ function team($, teamName) {
}
}
- $("#mkwsLang").html(data);
+ $(".mkwsLang.mkwsTeam_" + m_teamName).html(data);
}
- function mkws_resize_page () {
- var list = ["mkwsSwitch"];
-
- var width = mkws_config.responsive_design_width;
- var parentId = $("#mkwsTermlists").parent().attr('id');
-
- if ($(window).width() <= width &&
- parentId === "mkwsTermlistContainer1") {
- debug("changing from wide to narrow: " + $(window).width());
- $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer2"));
- $("#mkwsTermlistContainer1").hide();
- $("#mkwsTermlistContainer2").show();
- for(var i = 0; i < list.length; i++) {
- $("#" + list[i]).hide();
- }
- } else if ($(window).width() > width &&
- parentId === "mkwsTermlistContainer2") {
- debug("changing from narrow to wide: " + $(window).width());
- $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer1"));
- $("#mkwsTermlistContainer1").show();
- $("#mkwsTermlistContainer2").hide();
- for(var i = 0; i < list.length; i++) {
- $("#" + list[i]).show();
- }
- }
- };
-
-
/* locale */
function M(word) {
var lang = mkws_config.lang;
@@ -1307,15 +1290,23 @@ function _mkws_jquery_plugin ($) {
var id = 'mkws' + ids[i];
var node = $('#' + id);
if (node.attr('id')) {
- node.addClass(id + " mkwsTeam_AUTO");
- log("added magic classes to '" + node.attr('id') + "'");
+ node.addClass(id);
+ log("added magic class to '" + node.attr('id') + "'");
}
}
- // Find all nodes with class (NOT id) mkwsRecords, and
- // determine their team from the mkwsTeam_* class. So:
- //
- $('.mkwsSearch, .mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () {
+ // For all MKWS-classed nodes that don't have a team
+ // specified, set the team to AUTO.
+ $('[class^="mkws"],[class*=" mkws"]').each(function () {
+ if (!this.className.match(/mkwsTeam_/)) {
+ log("adding AUTO team to node with class '" + this.className + "'");
+ $(this).addClass('mkwsTeam_AUTO');
+ }
+ });
+
+ // Find all nodes with an class, and determine their team from
+ // the mkwsTeam_* class. Make all team objects.
+ $('[class^="mkws"],[class*=" mkws"]').each(function () {
var node = this;
mkws.handle_node_with_team(node, function(tname) {
if (mkws.teams[tname]) {
@@ -1348,12 +1339,42 @@ function _mkws_jquery_plugin ($) {
tname = cname.replace(/^mkwsTeam_/, '');
}
}
- if (!tname)
- tname = "AUTO";
callback(tname);
}
+ mkws.resize_page = function () {
+ var list = ["mkwsSwitch", "mkwsLang"];
+
+ var width = mkws_config.responsive_design_width;
+ var parent = $(".mkwsTermlists").parent();
+
+ if ($(window).width() <= width &&
+ parent.hasClass("mkwsTermlistContainer1")) {
+ log("changing from wide to narrow: " + $(window).width());
+ $(".mkwsTermlistContainer1").hide();
+ $(".mkwsTermlistContainer2").show();
+ for (var tname in mkws.teams) {
+ $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer2.mkwsTeam_" + tname));
+ for(var i = 0; i < list.length; i++) {
+ $("." + list[i] + ".mkwsTeam_" + tname).hide();
+ }
+ }
+ } else if ($(window).width() > width &&
+ parent.hasClass("mkwsTermlistContainer2")) {
+ log("changing from narrow to wide: " + $(window).width());
+ $(".mkwsTermlistContainer1").show();
+ $(".mkwsTermlistContainer2").hide();
+ for (var tname in mkws.teams) {
+ $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer1.mkwsTeam_" + tname));
+ for(var i = 0; i < list.length; i++) {
+ $("." + list[i] + ".mkwsTeam_" + tname).show();
+ }
+ }
+ }
+ };
+
+
mkws.showDetails = function (prefixRecId, tname) {
mkws.teams[tname].showDetails(prefixRecId);
}
@@ -1375,7 +1396,7 @@ function _mkws_jquery_plugin ($) {
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 */
+ facets: ["xtargets", "subject", "author"], /* 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 */
@@ -1410,11 +1431,11 @@ function _mkws_jquery_plugin ($) {
* for the site.
*/
function authenticate_session(auth_url, auth_domain, pp2_url) {
- console.log("Run service proxy auth URL: " + auth_url);
+ log("Run service proxy auth URL: " + auth_url);
if (!auth_domain) {
auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2');
- console.log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
+ log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
}
var request = new pzHttpRequest(auth_url, function(err) {
@@ -1433,7 +1454,7 @@ function _mkws_jquery_plugin ($) {
return;
}
- console.log("Service proxy auth successfully done");
+ log("Service proxy auth successfully done");
mkws.authenticated = true;
run_auto_searches();
});
@@ -1441,13 +1462,13 @@ function _mkws_jquery_plugin ($) {
function run_auto_searches() {
- console.log("running auto searches");
+ log("running auto searches");
for (var teamName in mkws.teams) {
// ### should check mkwsTermlist as well, for facet-only teams
var node = $('.mkwsRecords.mkwsTeam_' + teamName);
var query = node.attr('autosearch');
- console.log("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query);
+ log("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query);
if (query) {
var sort = node.attr('sort');
@@ -1456,9 +1477,9 @@ function _mkws_jquery_plugin ($) {
if (teamName) s += " [teamName '" + teamName + "']";
if (sort) s += " sorted by '" + sort + "'";
if (targets) s += " in targets '" + targets + "'";
- console.log(s);
+ log(s);
var team = mkws.teams[teamName];
- console.log($.toJSON(team));
+ log($.toJSON(team));
team.newSearch(query, sort, targets, teamName);
}
}