\
-';
- } 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();
-
- // ### Should not be in the team code, since window size is global
- 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() });
- // initial check after page load
- $(document).ready(function() { mkws.resize_page() });
- }
+ mkwsHtmlSwitch();
var node;
node = findnode('.mkwsSearchForm');
@@ -989,106 +832,35 @@ function team($, teamName) {
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 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 = [];
@@ -1130,16 +902,73 @@ function team($, teamName) {
}
- that.run_auto_search = function() {
- // ### should check mkwsTermlist as well, for facet-only teams
- var node = findnode('.mkwsRecords');
+ 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() {
+ 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");
@@ -1156,29 +985,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;
@@ -1190,10 +1012,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 = $.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 {
- mkws_html_all()
+ mkwsHtmlAll()
}
catch (e) {
@@ -1229,7 +1131,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) {
@@ -1237,7 +1139,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+/)
@@ -1255,7 +1157,7 @@ function team($, teamName) {
}
- mkws.resize_page = function () {
+ mkws.resizePage = function () {
var list = ["mkwsSwitch", "mkwsLang"];
var width = mkws_config.responsive_design_width;
@@ -1324,7 +1226,98 @@ function team($, teamName) {
}
- function default_mkws_config() {
+ // 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 '\
+