return that;
+ // Functions follow for promoting the regular widget object into
+ // widgets of specific types. These could be moved outside of the
+ // widget object, or even into their own source files.
+
function promoteTargets() {
team.queue("targets").subscribe(function(data) {
if (node.length === 0) alert("huh?!");
var detRecordDiv = document.getElementById('mkwsDet_' + teamName + '_' + data.recid);
if (detRecordDiv) return;
m_curDetRecData = data;
+ // Can't use jQuery's $('#x') syntax to find this ID, because it contains spaces.
var recordDiv = document.getElementById('mkwsRecdiv_' + teamName + '_' + m_curDetRecData.recid);
var html = renderDetails(m_curDetRecData);
- recordDiv.innerHTML += html;
+ $(recordDiv).append(html);
}
function mkwsSetLang() {
- var lang = parseQuerystring().lang || mkws_config.lang;
+ var lang = mkws.parseQuerystring().lang || mkws_config.lang;
if (!lang || !mkws.locale_lang[lang]) {
mkws_config.lang = ""
} else {
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");
}
- // 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;
- }
-
-
- // 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 */
+ // 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;
var source = node.html();
if (!source) {
- source = defaultTemplate(name);
+ source = mkws.defaultTemplate(name);
}
template = Handlebars.compile(source);
}
- function defaultTemplate(name)
- {
- if (name === 'Record') {
- return '\
-<table>\
- <tr>\
- <th>{{translate "Title"}}</th>\
- <td>\
- {{md-title}}\
- {{#if md-title-remainder}}\
- ({{md-title-remainder}})\
- {{/if}}\
- {{#if md-title-responsibility}}\
- <i>{{md-title-responsibility}}</i>\
- {{/if}}\
- </td>\
- </tr>\
- {{#if md-date}}\
- <tr>\
- <th>{{translate "Date"}}</th>\
- <td>{{md-date}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-author}}\
- <tr>\
- <th>{{translate "Author"}}</th>\
- <td>{{md-author}}</td>\
- </tr>\
- {{/if}}\
- {{#if md-electronic-url}}\
- <tr>\
- <th>{{translate "Links"}}</th>\
- <td>\
- {{#each md-electronic-url}}\
- <a href="{{this}}">Link{{index1}}</a>\
- {{/each}}\
- </td>\
- </tr>\
- {{/if}}\
- {{#if-any location having="md-subject"}}\
- <tr>\
- <th>{{translate "Subject"}}</th>\
- <td>\
- {{#first location having="md-subject"}}\
- {{#if md-subject}}\
- {{#commaList md-subject}}\
- {{this}}{{/commaList}}\
- {{/if}}\
- {{/first}}\
- </td>\
- </tr>\
- {{/if-any}}\
- <tr>\
- <th>{{translate "Locations"}}</th>\
- <td>\
- {{#commaList location}}\
- {{attr "@name"}}{{/commaList}}\
- </td>\
- </tr>\
-</table>\
-';
- } else if (name === "Summary") {
- return '\
-<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
- <b>{{md-title}}</b>\
-</a>\
-{{#if md-title-remainder}}\
- <span>{{md-title-remainder}}</span>\
-{{/if}}\
-{{#if md-title-responsibility}}\
- <span><i>{{md-title-responsibility}}</i></span>\
-{{/if}}\
-';
- }
-
- var s = "There is no default '" + name +"' template!";
- alert(s);
- return s;
- }
-
-
// The following PubSub code is modified from the jQuery manual:
// https://api.jquery.com/jQuery.Callbacks/
//
}
+ // 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 '\
+<table>\
+ <tr>\
+ <th>{{translate "Title"}}</th>\
+ <td>\
+ {{md-title}}\
+ {{#if md-title-remainder}}\
+ ({{md-title-remainder}})\
+ {{/if}}\
+ {{#if md-title-responsibility}}\
+ <i>{{md-title-responsibility}}</i>\
+ {{/if}}\
+ </td>\
+ </tr>\
+ {{#if md-date}}\
+ <tr>\
+ <th>{{translate "Date"}}</th>\
+ <td>{{md-date}}</td>\
+ </tr>\
+ {{/if}}\
+ {{#if md-author}}\
+ <tr>\
+ <th>{{translate "Author"}}</th>\
+ <td>{{md-author}}</td>\
+ </tr>\
+ {{/if}}\
+ {{#if md-electronic-url}}\
+ <tr>\
+ <th>{{translate "Links"}}</th>\
+ <td>\
+ {{#each md-electronic-url}}\
+ <a href="{{this}}">Link{{index1}}</a>\
+ {{/each}}\
+ </td>\
+ </tr>\
+ {{/if}}\
+ {{#if-any location having="md-subject"}}\
+ <tr>\
+ <th>{{translate "Subject"}}</th>\
+ <td>\
+ {{#first location having="md-subject"}}\
+ {{#if md-subject}}\
+ {{#commaList md-subject}}\
+ {{this}}{{/commaList}}\
+ {{/if}}\
+ {{/first}}\
+ </td>\
+ </tr>\
+ {{/if-any}}\
+ <tr>\
+ <th>{{translate "Locations"}}</th>\
+ <td>\
+ {{#commaList location}}\
+ {{attr "@name"}}{{/commaList}}\
+ </td>\
+ </tr>\
+</table>\
+';
+ } else if (name === "Summary") {
+ return '\
+<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
+ <b>{{md-title}}</b>\
+</a>\
+{{#if md-title-remainder}}\
+ <span>{{md-title-remainder}}</span>\
+{{/if}}\
+{{#if md-title-responsibility}}\
+ <span><i>{{md-title-responsibility}}</i></span>\
+{{/if}}\
+';
+ }
+
+ var s = "There is no default '" + name +"' template!";
+ alert(s);
+ return s;
+ }
+
+
function defaultMkwsConfig() {
/* default mkws config */
var config_default = {