\
-';
- } else if (name === "Summary") {
- return '\
-\
- {{md-title}}\
-\
-{{#if md-title-remainder}}\
- {{md-title-remainder}}\
-{{/if}}\
-{{#if md-title-responsibility}}\
- {{md-title-responsibility}}\
-{{/if}}\
-';
- }
-
- var s = "There is no default '" + name +"' template!";
- alert(s);
- return s;
- }
-
-
/*
* All the HTML stuff to render the search forms and
* result pages.
@@ -976,103 +849,32 @@ function team($, teamName) {
node.submit(onFormSubmitEventHandler);
node = findnode('.mkwsSort');
if (node.length)
- node.change(onSelectDdChange);
- node = findnode('.mkwsPerpage');
- if (node.length)
- node.change(onSelectDdChange);
-
- // on first page, hide the termlist
- $(document).ready(function() { findnode(".mkwsTermlists").hide(); });
- var motd = findnode(".mkwsMOTD");
- var container = findnode(".mkwsMOTDContainer");
- if (motd.length && container.length) {
- // Move the MOTD from the provided element down into the container
- motd.appendTo(container);
- }
- }
-
-
- // implement $.parseQuerystring() for parsing URL parameters
- function parseQuerystring() {
- var nvpair = {};
- var qs = window.location.search.replace('?', '');
- var pairs = qs.split('&');
- $.each(pairs, function(i, v){
- var pair = v.split('=');
- nvpair[pair[0]] = pair[1];
- });
- return nvpair;
- }
-
-
- function mkwsSetLang() {
- var lang = parseQuerystring().lang || mkws_config.lang;
- if (!lang || !mkws.locale_lang[lang]) {
- mkws_config.lang = ""
- } else {
- mkws_config.lang = lang;
- }
-
- debug("Locale language: " + (mkws_config.lang ? mkws_config.lang : "none"));
- return mkws_config.lang;
- }
-
-
- function mkwsHtmlSwitch() {
- debug("HTML switch for team " + m_teamName);
-
- var node = findnode(".mkwsSwitch");
- node.append($('' + M('Records') + ''));
- node.append($("", { text: " | " }));
- node.append($('' + M('Targets') + ''));
-
- debug("HTML targets");
- var node = findnode(".mkwsTargets");
- node.html('\
-
\
- No information available yet.\
-
');
- node.css("display", "none");
- }
-
-
- function mkwsHtmlSort() {
- debug("HTML sort, m_sort = '" + m_sort + "'");
- var sort_html = '';
+ node.change(onSelectDdChange);
+ node = findnode('.mkwsPerpage');
+ if (node.length)
+ node.change(onSelectDdChange);
- return sort_html;
+ // on first page, hide the termlist
+ $(document).ready(function() { findnode(".mkwsTermlists").hide(); });
+ var motd = findnode(".mkwsMOTD");
+ var container = findnode(".mkwsMOTDContainer");
+ if (motd.length && container.length) {
+ // Move the MOTD from the provided element down into the container
+ motd.appendTo(container);
+ }
}
- function mkwsHtmlPerpage() {
- debug("HTML perpage, m_perpage = " + m_perpage);
- var perpage_html = '';
- return perpage_html;
+ debug("Locale language: " + (mkws_config.lang ? mkws_config.lang : "none"));
+ return mkws_config.lang;
}
@@ -1119,16 +921,73 @@ function team($, teamName) {
}
+ function mkwsHtmlSort() {
+ debug("HTML sort, m_sortOrder = '" + m_sortOrder + "'");
+ var sort_html = '';
+
+ return sort_html;
+ }
+
+
+ function mkwsHtmlPerpage() {
+ debug("HTML perpage, m_perpage = " + m_perpage);
+ var perpage_html = '';
+
+ return perpage_html;
+ }
+
+
+ function mkwsHtmlSwitch() {
+ debug("HTML switch for team " + m_teamName);
+
+ var node = findnode(".mkwsSwitch");
+ node.append($('' + M('Records') + ''));
+ node.append($("", { text: " | " }));
+ node.append($('' + M('Targets') + ''));
+
+ debug("HTML targets");
+ var node = findnode(".mkwsTargets");
+ node.html('\
+
\
+ No information available yet.\
+
');
+ node.css("display", "none");
+ }
+
+
that.runAutoSearch = function() {
- // ### should check mkwsTermlist as well, for facet-only teams
- var node = findnode('.mkwsRecords');
+ var node = findnode('.mkwsRecords,.mkwsTermlists');
var query = node.attr('autosearch');
if (!query)
return;
if (query.match(/^!param!/)) {
var param = query.replace(/^!param!/, '');
- query = getParameterByName(param);
+ query = mkws.getParameterByName(param);
debug("obtained query '" + query + "' from param '" + param + "'");
if (!query) {
alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter");
@@ -1145,29 +1004,22 @@ function team($, teamName) {
debug("node=" + node + ", class='" + node.className + "', query=" + query);
- var sort = node.attr('sort');
+ var sortOrder = node.attr('sort');
var targets = node.attr('targets');
var s = "running auto search: '" + query + "'";
- if (sort) s += " sorted by '" + sort + "'";
+ if (sortOrder) s += " sorted by '" + sortOrder + "'";
if (targets) s += " in targets '" + targets + "'";
debug(s);
- newSearch(query, sort, targets);
- }
-
-
- // This function is taken from a StackOverflow answer
- // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
- // ### should we unify this and parseQuerystring()?
- function getParameterByName(name) {
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
- results = regex.exec(location.search);
- return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+ newSearch(query, sortOrder, targets);
}
- /* locale */
+ // Translation function. At present, this is properly a
+ // global-level function (hence the assignment to mkws.M) but we
+ // want to make it per-team so different teams can operate in
+ // different languages.
+ //
function M(word) {
var lang = mkws_config.lang;
@@ -1179,6 +1031,86 @@ function team($, teamName) {
mkws.M = M; // so the Handlebars helper can use it
+ // Finds the node of the specified class within the current team
+ // Multiple OR-clauses separated by commas are handled
+ // More complex cases may not work
+ //
+ function findnode(selector, teamName) {
+ teamName = teamName || m_teamName;
+
+ selector = $.map(selector.split(','), function(s, i) {
+ return s + '.mkwsTeam_' + teamName;
+ }).join(',');
+
+ return $(selector);
+ }
+
+
+ function renderSummary(hit)
+ {
+ var template = loadTemplate("Summary");
+ hit._id = "mkwsRec_" + hit.recid;
+ hit._onclick = "mkws.showDetails('" + m_teamName + "', this.id);return false;"
+ return template(hit);
+ }
+
+
+ function renderDetails(data, marker)
+ {
+ var template = loadTemplate("Record");
+ var details = template(data);
+ return '
' + details + '
';
+ }
+
+
+ function loadTemplate(name)
+ {
+ var template = m_template[name];
+
+ if (template === undefined) {
+ // Fall back to generic template if there is no team-specific one
+ var node = findnode(".mkwsTemplate_" + name);
+ if (!node.length) {
+ node = findnode(".mkwsTemplate_" + name, "ALL");
+ }
+
+ var source = node.html();
+ if (!source) {
+ source = mkws.defaultTemplate(name);
+ }
+
+ template = Handlebars.compile(source);
+ debug("compiled template '" + name + "'");
+ m_template[name] = template;
+ }
+
+ return template;
+ }
+
+
+ // The following PubSub code is modified from the jQuery manual:
+ // https://api.jquery.com/jQuery.Callbacks/
+ //
+ // Use as:
+ // team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
+ // team.queue("eventName").publish(arg1, arg2, ...);
+
+ var queues = {};
+ var queue = function(id) {
+ if (!queues[id]) {
+ var callbacks = $.Callbacks();
+ queues[id] = {
+ publish: callbacks.fire,
+ subscribe: callbacks.add,
+ unsubscribe: callbacks.remove
+ };
+ }
+ return queues[id];
+ }
+
+ that.queue = queue;
+
+
// main
(function() {
try {
@@ -1313,6 +1245,97 @@ function team($, teamName) {
}
+ // This function is taken from a StackOverflow answer
+ // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
+ mkws.getParameterByName = function(name) {
+ name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+ var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
+ results = regex.exec(location.search);
+ return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
+ }
+
+
+ mkws.defaultTemplate = function(name)
+ {
+ if (name === 'Record') {
+ return '\
+
\
+';
+ } else if (name === "Summary") {
+ return '\
+\
+ {{md-title}}\
+\
+{{#if md-title-remainder}}\
+ {{md-title-remainder}}\
+{{/if}}\
+{{#if md-title-responsibility}}\
+ {{md-title-responsibility}}\
+{{/if}}\
+';
+ }
+
+ var s = "There is no default '" + name +"' template!";
+ alert(s);
+ return s;
+ }
+
+
function defaultMkwsConfig() {
/* default mkws config */
var config_default = {
@@ -1431,6 +1454,12 @@ function team($, teamName) {
$(document).ready(function() { mkws.resizePage() });
}
+ // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp"
+ if (mkws_config.pazpar2_url.match(/^\/\//)) {
+ mkws_config.pazpar2_url = document.location.protocol + mkws_config.pazpar2_url;
+ debug("adjust protocol independent links: " + mkws_config.pazpar2_url);
+ }
+
// Backwards compatibility: set new magic class names on any
// elements that have the old magic IDs.
var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",
@@ -1454,7 +1483,7 @@ function team($, teamName) {
}
});
- // Find all nodes with an class, and determine their team from
+ // Find all nodes with an MKWS class, and determine their team from
// the mkwsTeam_* class. Make all team objects.
var then = $.now();
$('[class^="mkws"],[class*=" mkws"]').each(function () {
@@ -1463,6 +1492,14 @@ function team($, teamName) {
mkws.teams[tname] = team(j, tname);
debug("Made MKWS team '" + tname + "'");
}
+ });
+ });
+ // Second pass: make the individual widget objects. This has
+ // to be done separately, and after the team-creation, since
+ // that sometimes makes new widget nodes (e.g. creating
+ // mkwsTermlists instead mkwsResults.
+ $('[class^="mkws"],[class*=" mkws"]').each(function () {
+ mkws.handleNodeWithTeam(this, function(tname, type) {
var myTeam = mkws.teams[tname];
var myWidget = widget(j, myTeam, type, this);
});