X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;ds=sidebyside;f=tools%2Fhtdocs%2Fmkws.js;h=2d9b452780e646dd9addabc6fa15b058e939b00a;hb=588ec81e46383127b62dc1e9d0b454dfe2637967;hp=624521585f39d3fa5c6adf89a5f6b53900dfaf44;hpb=60a397929857c23ce4d319825dffd2e2bd150e25;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 6245215..2d9b452 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
@@ -83,6 +86,7 @@ var mkws = {
"Authors": "Autoren",
"Subjects": "Schlagwörter",
"Sources": "Daten und Quellen",
+ "source": "datenquelle",
"Termlists": "Termlisten",
"Next": "Weiter",
"Prev": "Zurück",
@@ -96,8 +100,10 @@ var mkws = {
"found": "gefunden",
"Title": "Titel",
"Author": "Autor",
+ "author": "autor",
"Date": "Datum",
"Subject": "Schlagwort",
+ "subject": "schlagwort",
"Location": "Ort",
"Records": "Datensätze",
"Targets": "Datenbanken",
@@ -109,6 +115,7 @@ var mkws = {
"Authors": "Forfattere",
"Subjects": "Emner",
"Sources": "Kilder",
+ "source": "kilder",
"Termlists": "Termlists",
"Next": "Næste",
"Prev": "Forrige",
@@ -122,8 +129,10 @@ var mkws = {
"found": "fandt",
"Title": "Title",
"Author": "Forfatter",
+ "author": "forfatter",
"Date": "Dato",
"Subject": "Emneord",
+ "subject": "emneord",
"Location": "Lokation",
"Records": "Poster",
"Targets": "Baser",
@@ -141,7 +150,7 @@ if (mkws_config == null || typeof mkws_config != 'object') {
// wrapper for jQuery lib
-function _make_mkws_team($, teamName) {
+function team($, teamName) {
var that = {};
var m_teamName = teamName;
var m_submitted = false;
@@ -162,10 +171,11 @@ function _make_mkws_team($, teamName) {
// if (console && console.log) // disabled, will fail in IE8
- // console.log("run _make_mkws_team(" + (teamName ? teamName : "") + ")");
+ // console.log("run team(" + (teamName ? teamName : "") + ")");
- // Needs to be defined inside _make_mkws_team() so it can see m_debug_time
+ // Needs to be defined inside team() so it can see m_debug_time
+ // ### member access won't work: there is only one instance of this function
mkws.debug_function = function (string) {
if (!mkws.debug_level)
return;
@@ -224,8 +234,8 @@ function _make_mkws_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?)
@@ -270,7 +280,8 @@ function _make_mkws_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(''));
@@ -281,55 +292,57 @@ function _make_mkws_team($, teamName) {
{
var template = loadTemplate("Summary");
hit._id = "mkwsRec_" + hit.recid;
- hit._onclick = "mkws.showDetails(this.id);return false;"
+ hit._onclick = "mkws.showDetails(this.id, '" + m_teamName + "');return false;"
return template(hit);
}
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('
' + M('Termlists') + '
');
var facets = mkws_config.facets;
for(var i = 0; i < facets.length; i++) {
- if (facets[i] == "sources") {
+ if (facets[i] == "xtargets") {
add_single_facet(acc, "Sources", data.xtargets, 16, null);
- } else if (facets[i] == "subjects") {
+ } else if (facets[i] == "subject") {
add_single_facet(acc, "Subjects", data.subject, 10, "subject");
- } else if (facets[i] == "authors") {
+ } else if (facets[i] == "author") {
add_single_facet(acc, "Authors", data.author, 10, "author");
} else {
alert("bad facet configuration: '" + facets[i] + "'");
}
}
- var termlist = $("#mkwsTermlists");
- if (termlist)
- termlist.html(acc.join(''));
+ node.html(acc.join(''));
}
@@ -355,7 +368,7 @@ function _make_mkws_team($, teamName) {
}
- function my_onrecord(data, teamName) {
+ function my_onrecord(data, args, teamName) {
debug("record for " + teamName);
// FIXME: record is async!!
clearTimeout(m_paz.recordTimer);
@@ -371,9 +384,8 @@ function _make_mkws_team($, teamName) {
function my_onbytarget(data, teamName) {
debug("target for " + teamName);
- var targetDiv = document.getElementById("mkwsBytarget");
+ var targetDiv = $('.mkwsBytarget.mkwsTeam_' + teamName);
if (!targetDiv) {
- // No mkwsTargets div.
return;
}
@@ -394,7 +406,7 @@ function _make_mkws_team($, teamName) {
}
table += '';
- targetDiv.innerHTML = table;
+ targetDiv.html(table);
}
////////////////////////////////////////////////////////////////////////////////
@@ -404,9 +416,17 @@ function _make_mkws_team($, teamName) {
// wait until the DOM is ready
function domReady ()
{
- document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler;
- document.mkwsSearchForm.mkwsQuery.value = '';
+ $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) {
+ debug("adding search-forms for team '" + m_teamName + "'");
+ var node = this;
+ mkws.handle_node_with_team(node, function(tname) {
+ debug("adding search-form '" + tname + "' for team '" + m_teamName + "'");
+ $(node).submit(onFormSubmitEventHandler);
+ });
+ });
+
if (document.mkwsSelect) {
+ debug("messing with mkwsSelect");
if (document.mkwsSelect.mkwsSort)
document.mkwsSelect.mkwsSort.onchange = onSelectDdChange;
if (document.mkwsSelect.mkwsPerpage)
@@ -418,7 +438,11 @@ function _make_mkws_team($, teamName) {
// when search button pressed
function onFormSubmitEventHandler()
{
- that.newSearch(document.mkwsSearchForm.mkwsQuery.value);
+ mkws.handle_node_with_team(this, function (tname) {
+ var val = $('.mkwsQuery.mkwsTeam_' + tname).val();
+ mkws.teams[tname].newSearch(val);
+ });
+
return false;
}
@@ -437,7 +461,7 @@ function _make_mkws_team($, teamName) {
resetPage(); // ### the globals it resents should be indexed by windowid
loadSelect(); // ### should use windowid
triggerSearch(query, sort, targets, windowid);
- mkws.switchView('records'); // In case it's configured to start off as hidden
+ mkws.switchView(m_teamName, 'records'); // In case it's configured to start off as hidden
m_submitted = true;
}
@@ -604,10 +628,10 @@ function _make_mkws_team($, teamName) {
}
var filter = m_filters[i];
if (filter.id) {
- text += 'Source: ' + filter.name + '';
} else {
- text += filter.field + ': ' + filter.value + '';
}
@@ -687,33 +711,33 @@ function _make_mkws_team($, teamName) {
// switching view between targets and records
- mkws.switchView = function(view) {
- debug("switchView: " + view);
+ mkws.switchView = function(tname, view) {
+ debug("switchView(" + tname + ", " + view + ")");
- var targets = document.getElementById('mkwsTargets');
- var results = document.getElementById('mkwsResults') ||
- document.getElementById('mkwsRecords');
- var blanket = document.getElementById('mkwsBlanket');
- var motd = document.getElementById('mkwsMOTD');
+ var targets = $('.mkwsTargets.mkwsTeam_' + tname);
+ var results = $('.mkwsResults.mkwsTeam_' + tname + ',.mkwsRecords.mkwsTeam_' + tname);
+ var blanket = $('.mkwsBlanket.mkwsTeam_' + tname);
+ var motd = $('.mkwsMOTD.mkwsTeam_' + tname);
switch(view) {
case 'targets':
- if (targets) targets.style.display = "block";
- if (results) results.style.display = "none";
- if (blanket) blanket.style.display = "none";
- if (motd) motd.style.display = "none";
+ if (targets) targets.css('display', 'block');
+ if (results) results.css('display', 'none');
+ if (blanket) blanket.css('display', 'none');
+ if (motd) motd.css('display', 'none');
break;
case 'records':
- if (targets) targets.style.display = "none";
- if (results) results.style.display = "block";
- if (blanket) blanket.style.display = "block";
- if (motd) motd.style.display = "none";
+ if (targets) targets.css('display', 'none');
+ if (results) results.css('display', 'block');
+ if (blanket) blanket.css('display', 'block');
+ if (motd) motd.css('display', 'none');
break;
case 'none':
- if (targets) targets.style.display = "none";
- if (results) results.style.display = "none";
- if (blanket) blanket.style.display = "none";
- if (motd) motd.style.display = "none";
+ alert("mkws.switchView(" + tname + ", 'none') shouldn't happen");
+ if (targets) targets.css('display', 'none');
+ if (results) results.css('display', 'none');
+ if (blanket) blanket.css('display', 'none');
+ if (motd) motd.css('display', 'none');
break;
default:
alert("Unknown view '" + view + "'");
@@ -722,7 +746,7 @@ function _make_mkws_team($, teamName) {
// detailed record drawing
- mkws.showDetails = function (prefixRecId) {
+ that.showDetails = function (prefixRecId) {
var recId = prefixRecId.replace('mkwsRec_', '');
var oldRecId = m_curDetRecId;
m_curDetRecId = recId;
@@ -863,7 +887,8 @@ function _make_mkws_team($, teamName) {
// For some reason, doing this programmatically results in
// document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
debug("HTML search form");
- $('.mkwsSearch').each(function (i, obj) {
+ // ### There is only one match here by design: fix not to bother looping
+ $('.mkwsSearch.mkwsTeam_' + m_teamName).each(function (i, obj) {
var node = this;
mkws.handle_node_with_team(node, function(tname) {
$(node).html('\
@@ -875,31 +900,32 @@ function _make_mkws_team($, teamName) {
});
debug("HTML records");
- // If the application has an #mkwsResults, populate it in the
- // usual way. If not, assume that it's a smarter application that
- // defines its own subcomponents:
- // #mkwsTermlists
- // #mkwsRanking
- // #mkwsPager
- // #mkwsNavi
- // #mkwsRecords
- if ($("#mkwsResults").length) {
- $("#mkwsResults").html('\
+ // If the team has a .mkwsResults, populate it in the usual
+ // way. If not, assume that it's a smarter application that
+ // defines its own subcomponents, some or all of the
+ // following:
+ // .mkwsTermlists
+ // .mkwsRanking
+ // .mkwsPager
+ // .mkwsNavi
+ // .mkwsRecords
+ if ($(".mkwsResults.mkwsTeam_" + m_teamName).length) {
+ $(".mkwsResults.mkwsTeam_" + m_teamName).html('\
\
\
- \
- \
+ | \
+ \
| \
- \
- \
- \
- \
- \
+ | \
+ \
+ \
+ \
+ \
| \
\
\
\
- \
+ \
| \
\
');
@@ -924,21 +950,23 @@ function _make_mkws_team($, teamName) {
if (mkws_config.responsive_design_width) {
// Responsive web design - change layout on the fly based on
// current screen width. Required for mobile devices.
- $(window).resize(function(e) { mkws_resize_page() });
+ $(window).resize(function(e) { mkws.resize_page() });
// initial check after page load
- $(document).ready(function() { mkws_resize_page() });
+ $(document).ready(function() { mkws.resize_page() });
}
+ debug("before domReady()");
domReady();
+ debug("after domReady()");
// on first page, hide the termlist
- $(document).ready(function() { $("#mkwsTermlists").hide(); });
- var motd = document.getElementById("mkwsMOTD");
- var container = document.getElementById("mkwsMOTDContainer");
- if (motd && container) {
+ $(document).ready(function() { $(".mkwsTermlists.mkwsTeam_" + m_teamName).hide(); });
+ var motd = $(".mkwsMOTD.mkwsTeam_" + m_teamName);
+ var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName);
+ debug("for team '" + m_teamName + "', motd=" + motd + "(" + motd.length + "), container=" + container + "(" + container.length + ")");
+ if (motd.length && container.length) {
// Move the MOTD from the provided element down into the container
- motd.parentNode.removeChild(motd);
- container.appendChild(motd);
+ motd.appendTo(container);
}
}
@@ -970,18 +998,20 @@ function _make_mkws_team($, teamName) {
function mkws_html_switch() {
- debug("HTML switch");
+ debug("HTML switch for team " + m_teamName);
- $("#mkwsSwitch").append($('' + M('Records') + ''));
- $("#mkwsSwitch").append($("", { text: " | " }));
- $("#mkwsSwitch").append($('' + M('Targets') + ''));
+ var node = $(".mkwsSwitch.mkwsTeam_" + m_teamName);
+ node.append($('' + M('Records') + ''));
+ node.append($("", { text: " | " }));
+ node.append($('' + M('Targets') + ''));
debug("HTML targets");
- $("#mkwsTargets").html('\
-\
+ var node = $(".mkwsTargets.mkwsTeam_" + m_teamName);
+ node.html('\
+
\
No information available yet.\
');
- $("#mkwsTargets").css("display", "none");
+ node.css("display", "none");
}
@@ -1033,18 +1063,18 @@ function _make_mkws_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(", "));
@@ -1064,38 +1094,10 @@ function _make_mkws_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;
@@ -1269,7 +1271,7 @@ function _mkws_jquery_plugin ($) {
};
-// wrapper to call _make_mkws_team() after page load
+// wrapper to call team() after page load
(function (j) {
function log(s) {
if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
@@ -1294,21 +1296,29 @@ 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:
- //
- $('.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]) {
log("MKWS team '" + tname + "' already exists, skipping");
} else {
- mkws.teams[tname] = _make_mkws_team(j, tname);
+ mkws.teams[tname] = team(j, tname);
log("Made MKWS team '" + tname + "'");
}
});
@@ -1335,12 +1345,47 @@ 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);
+ }
+
+
function default_mkws_config() {
/* default mkws config */
var config_default = {
@@ -1357,7 +1402,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 */
@@ -1392,11 +1437,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) {
@@ -1415,7 +1460,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();
});
@@ -1423,13 +1468,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');
@@ -1438,9 +1483,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);
}
}