\
-';
- } 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.
*/
- // ### This and other multi-word identifiers should be camelCase
- function mkws_html_all() {
- mkws_set_lang();
+ function mkwsHtmlAll() {
+ mkwsSetLang();
if (mkws_config.show_lang)
- mkws_html_lang();
+ mkwsHtmlLang();
debug("HTML search form");
- mkws.handle_node_with_team(findnode('.mkwsSearch'), function(tname) {
+ mkws.handleNodeWithTeam(findnode('.mkwsSearch'), function(tname) {
this.html('\
';
node.html(ranking_data);
}
- mkws_html_switch();
+ mkwsHtmlSwitch();
var node;
node = findnode('.mkwsSearchForm');
@@ -986,99 +839,28 @@ function team($, teamName) {
$(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 mkws_set_lang() {
- 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 mkws_html_switch() {
- 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 mkws_html_sort() {
- debug("HTML sort, m_sort = '" + m_sort + "'");
- var sort_html = '';
-
- return sort_html;
}
- function mkws_html_perpage() {
- 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;
}
/* create locale language menu */
- function mkws_html_lang() {
+ function mkwsHtmlLang() {
var lang_default = "en";
var lang = mkws_config.lang || lang_default;
var list = [];
@@ -1120,7 +902,65 @@ function team($, teamName) {
}
- that.run_auto_search = function() {
+ function mkwsHtmlSort() {
+ debug("HTML sort, m_sort = '" + m_sort + "'");
+ 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 query = node.attr('autosearch');
@@ -1129,7 +969,7 @@ function team($, teamName) {
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");
@@ -1157,17 +997,6 @@ 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
- // ### 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, " "));
- }
-
-
/* locale */
function M(word) {
var lang = mkws_config.lang;
@@ -1180,10 +1009,90 @@ 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 = selector.split(',').map(function(s) {
+ 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 {
- mkws_html_all()
+ mkwsHtmlAll()
}
catch (e) {
@@ -1219,7 +1128,7 @@ function team($, teamName) {
var debug = mkws.debug;
- mkws.handle_node_with_team = function(node, callback) {
+ mkws.handleNodeWithTeam = function(node, callback) {
// First branch for DOM objects; second branch for jQuery objects
var classes = node.className || node.attr('class');
if (!classes) {
@@ -1227,7 +1136,7 @@ function team($, teamName) {
// undefined, we don't get an error message, but this
// function and its callers, up several stack level,
// silently return. What a crock.
- mkws.debug("handle_node_with_team() called on node with no classes");
+ mkws.debug("handleNodeWithTeam() called on node with no classes");
return;
}
var list = classes.split(/\s+/)
@@ -1245,7 +1154,7 @@ function team($, teamName) {
}
- mkws.resize_page = function () {
+ mkws.resizePage = function () {
var list = ["mkwsSwitch", "mkwsLang"];
var width = mkws_config.responsive_design_width;
@@ -1314,7 +1223,112 @@ function team($, teamName) {
}
- function default_mkws_config() {
+ // implement $.parseQuerystring() for parsing URL parameters
+ mkws.parseQuerystring = function() {
+ 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;
+ }
+
+
+ // 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()?
+ 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 '\
+