Merge remote branch 'origin/master' into wosch
authorWolfram Schneider <wosch@indexdata.dk>
Wed, 7 May 2014 12:38:24 +0000 (12:38 +0000)
committerWolfram Schneider <wosch@indexdata.dk>
Wed, 7 May 2014 12:38:24 +0000 (12:38 +0000)
14 files changed:
examples/htdocs/mkws-widget-reference.js
src/mkws-core.js
src/mkws-filter.js
src/mkws-handlebars.js
src/mkws-jquery.js
src/mkws-team.js
src/mkws-widget-authname.js
src/mkws-widget-builder.js
src/mkws-widget-categories.js
src/mkws-widget-log.js
src/mkws-widget-main.js
src/mkws-widget-record.js
src/mkws-widget-termlists.js
src/mkws-widget.js

index 20e701a..7bccbcf 100644 (file)
@@ -1,9 +1,9 @@
 mkws.registerWidgetType('Reference', function() {
-    mkws.promotionFunction('Record').call(this);
-    if (!this.config.target) this.config.target = 'wikimedia_wikipedia_single_result';
-    if (!this.config.template) this.config.template = 'Reference';
+  mkws.promotionFunction('Record').call(this);
+  if (!this.config.target) this.config.target = 'wikimedia_wikipedia_single_result';
+  if (!this.config.template) this.config.template = 'Reference';
 
-    this.team.registerTemplate('Reference', '\
+  this.team.registerTemplate('Reference', '\
   <img src="{{md-thumburl}}" alt="{{md-title}}">\
   <h1><a href="{{md-electronic-url}}">{{md-title}}</a></h1>\
 {{#if md-title-remainder}}\
index 1e84fca..87070f8 100644 (file)
 // authentication, and a hash of team objects, indexed by team-name.
 //
 var mkws = {
-    authenticated: false,
-    log_level: 1, // Will be overridden from mkws.config, but
-                  // initial value allows jQuery popup to use logging.
-    teams: {},
-    widgetType2function: {},
-
-    locale_lang: {
-       "de": {
-           "Authors": "Autoren",
-           "Subjects": "Schlagw&ouml;rter",
-           "Sources": "Daten und Quellen",
-           "source": "datenquelle",
-           "Termlists": "Termlisten",
-           "Next": "Weiter",
-           "Prev": "Zur&uuml;ck",
-           "Search": "Suche",
-           "Sort by": "Sortieren nach",
-           "and show": "und zeige",
-           "per page": "pro Seite",
-           "Displaying": "Zeige",
-           "to": "von",
-           "of": "aus",
-           "found": "gefunden",
-           "Title": "Titel",
-           "Author": "Autor",
-           "author": "autor",
-           "Date": "Datum",
-           "Subject": "Schlagwort",
-           "subject": "schlagwort",
-           "Location": "Ort",
-           "Records": "Datens&auml;tze",
-           "Targets": "Datenbanken",
-
-           "dummy": "dummy"
-       },
-
-       "da": {
-           "Authors": "Forfattere",
-           "Subjects": "Emner",
-           "Sources": "Kilder",
-           "source": "kilder",
-           "Termlists": "Termlists",
-           "Next": "N&aelig;ste",
-           "Prev": "Forrige",
-           "Search": "S&oslash;g",
-           "Sort by": "Sorter efter",
-           "and show": "og vis",
-           "per page": "per side",
-           "Displaying": "Viser",
-           "to": "til",
-           "of": "ud af",
-           "found": "fandt",
-           "Title": "Title",
-           "Author": "Forfatter",
-           "author": "forfatter",
-           "Date": "Dato",
-           "Subject": "Emneord",
-           "subject": "emneord",
-           "Location": "Lokation",
-           "Records": "Poster",
-           "Targets": "Baser",
-
-           "dummy": "dummy"
-       }
+  authenticated: false,
+  log_level: 1, // Will be overridden from mkws.config, but
+                // initial value allows jQuery popup to use logging.
+  teams: {},
+  widgetType2function: {},
+
+  locale_lang: {
+    "de": {
+      "Authors": "Autoren",
+      "Subjects": "Schlagw&ouml;rter",
+      "Sources": "Daten und Quellen",
+      "source": "datenquelle",
+      "Termlists": "Termlisten",
+      "Next": "Weiter",
+      "Prev": "Zur&uuml;ck",
+      "Search": "Suche",
+      "Sort by": "Sortieren nach",
+      "and show": "und zeige",
+      "per page": "pro Seite",
+      "Displaying": "Zeige",
+      "to": "von",
+      "of": "aus",
+      "found": "gefunden",
+      "Title": "Titel",
+      "Author": "Autor",
+      "author": "autor",
+      "Date": "Datum",
+      "Subject": "Schlagwort",
+      "subject": "schlagwort",
+      "Location": "Ort",
+      "Records": "Datens&auml;tze",
+      "Targets": "Datenbanken",
+
+      "dummy": "dummy"
+    },
+
+    "da": {
+      "Authors": "Forfattere",
+      "Subjects": "Emner",
+      "Sources": "Kilder",
+      "source": "kilder",
+      "Termlists": "Termlists",
+      "Next": "N&aelig;ste",
+      "Prev": "Forrige",
+      "Search": "S&oslash;g",
+      "Sort by": "Sorter efter",
+      "and show": "og vis",
+      "per page": "per side",
+      "Displaying": "Viser",
+      "to": "til",
+      "of": "ud af",
+      "found": "fandt",
+      "Title": "Title",
+      "Author": "Forfatter",
+      "author": "forfatter",
+      "Date": "Dato",
+      "Subject": "Emneord",
+      "subject": "emneord",
+      "Location": "Lokation",
+      "Records": "Poster",
+      "Targets": "Baser",
+
+      "dummy": "dummy"
     }
+  }
 };
 
 
 mkws.log = function(string) {
-    if (!mkws.log_level)
-       return;
-
-    if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
-       return;
-    }
-
-    // you need to disable use strict at the top of the file!!!
-    if (mkws.log_level >= 3) {
-        // Works in Chrome; not sure about elsewhere
-       console.trace();
-    } else if (mkws.log_level >= 2) {
-       console.log(">>> called from function " + arguments.callee.caller.name + ' <<<');
-    }
-    console.log(string);
+  if (!mkws.log_level)
+    return;
+
+  if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
+    return;
+  }
+
+  // you need to disable use strict at the top of the file!!!
+  if (mkws.log_level >= 3) {
+    // Works in Chrome; not sure about elsewhere
+    console.trace();
+  } else if (mkws.log_level >= 2) {
+    console.log(">>> called from function " + arguments.callee.caller.name + ' <<<');
+  }
+  console.log(string);
 };
 
 
 // Translation function.
-mkws.M = function (word) {
-    var lang = mkws.config.lang;
+mkws.M = function(word) {
+  var lang = mkws.config.lang;
 
-    if (!lang || !mkws.locale_lang[lang])
-        return word;
+  if (!lang || !mkws.locale_lang[lang])
+    return word;
 
-    return mkws.locale_lang[lang][word] || word;
+  return mkws.locale_lang[lang][word] || word;
 };
 
 
 // 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, " "));
+  name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
+  var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
+  results = regex.exec(location.search);
+  return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
 }
 
 
 mkws.registerWidgetType = function(name, fn) {
-    mkws.widgetType2function[name] = fn;
-    mkws.log("registered widget-type '" + name + "'");
+  mkws.widgetType2function[name] = fn;
+  mkws.log("registered widget-type '" + name + "'");
 };
 
 mkws.promotionFunction = function(name) {
-    return mkws.widgetType2function[name];
+  return mkws.widgetType2function[name];
 };
 
 
 mkws.setMkwsConfig = function(overrides) {
-    // Set global log_level flag early so that mkws.log() works
-    // Fall back to old "debug_level" setting for backwards compatibility
-    var tmp = overrides.log_level;
-    if (typeof(tmp) === 'undefined') tmp = overrides.debug_level;
-    if (typeof(tmp) !== 'undefined') mkws.log_level = tmp;
-
-    var config_default = {
-       use_service_proxy: true,
-       pazpar2_url: "//mkws.indexdata.com/service-proxy/",
-       service_proxy_auth: "//mkws.indexdata.com/service-proxy-auth",
-       lang: "",
-       sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
-       perpage_options: [10, 20, 30, 50],
-       sort_default: "relevance",
-       perpage_default: 20,
-       query_width: 50,
-       show_lang: true,        /* show/hide language menu */
-       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: ["xtargets", "subject", "author"], /* display facets, in this order, [] for none */
-       responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
-       log_level: 1,     /* log level for development: 0..2 */
-
-       dummy: "dummy"
-    };
-
-    mkws.config = mkws.objectInheritingFrom(config_default);
-    for (var k in overrides) {
-       mkws.config[k] = overrides[k];
-    }
+  // Set global log_level flag early so that mkws.log() works
+  // Fall back to old "debug_level" setting for backwards compatibility
+  var tmp = overrides.log_level;
+  if (typeof(tmp) === 'undefined') tmp = overrides.debug_level;
+  if (typeof(tmp) !== 'undefined') mkws.log_level = tmp;
+
+  var config_default = {
+    use_service_proxy: true,
+    pazpar2_url: "//mkws.indexdata.com/service-proxy/",
+    service_proxy_auth: "//mkws.indexdata.com/service-proxy-auth",
+    lang: "",
+    sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
+    perpage_options: [10, 20, 30, 50],
+    sort_default: "relevance",
+    perpage_default: 20,
+    query_width: 50,
+    show_lang: true,    /* show/hide language menu */
+    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: ["xtargets", "subject", "author"], /* display facets, in this order, [] for none */
+    responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
+    log_level: 1,     /* log level for development: 0..2 */
+
+    dummy: "dummy"
+  };
+
+  mkws.config = mkws.objectInheritingFrom(config_default);
+  for (var k in overrides) {
+    mkws.config[k] = overrides[k];
+  }
 };
 
 
@@ -169,25 +169,25 @@ mkws.setMkwsConfig = function(overrides) {
 // but since the latter is not available in IE8 we can't use it.
 //
 mkws.objectInheritingFrom = function(o) {
-    function F() {}
-    F.prototype = o;
-    return new F();
+  function F() {}
+  F.prototype = o;
+  return new F();
 }
 
 
 mkws.defaultTemplate = function(name) {
-    if (name === 'Record') {
-       return '\
+  if (name === 'Record') {
+    return '\
 <table>\
   <tr>\
     <th>{{mkws-translate "Title"}}</th>\
     <td>\
       {{md-title}}\
       {{#if md-title-remainder}}\
-       ({{md-title-remainder}})\
+        ({{md-title-remainder}})\
       {{/if}}\
       {{#if md-title-responsibility}}\
-       <i>{{md-title-responsibility}}</i>\
+        <i>{{md-title-responsibility}}</i>\
       {{/if}}\
     </td>\
   </tr>\
@@ -208,7 +208,7 @@ mkws.defaultTemplate = function(name) {
     <th>{{mkws-translate "Links"}}</th>\
     <td>\
       {{#each md-electronic-url}}\
-       <a href="{{this}}">Link{{mkws-index1}}</a>\
+        <a href="{{this}}">Link{{mkws-index1}}</a>\
       {{/each}}\
     </td>\
   </tr>\
@@ -218,10 +218,10 @@ mkws.defaultTemplate = function(name) {
     <th>{{mkws-translate "Subject"}}</th>\
     <td>\
       {{#mkws-first location having="md-subject"}}\
-       {{#if md-subject}}\
-         {{#mkws-commaList md-subject}}\
-           {{this}}{{/mkws-commaList}}\
-       {{/if}}\
+        {{#if md-subject}}\
+          {{#mkws-commaList md-subject}}\
+            {{this}}{{/mkws-commaList}}\
+        {{/if}}\
       {{/mkws-first}}\
     </td>\
   </tr>\
@@ -230,13 +230,13 @@ mkws.defaultTemplate = function(name) {
     <th>{{mkws-translate "Locations"}}</th>\
     <td>\
       {{#mkws-commaList location}}\
-       {{mkws-attr "@name"}}{{/mkws-commaList}}\
+        {{mkws-attr "@name"}}{{/mkws-commaList}}\
     </td>\
   </tr>\
 </table>\
 ';
-    } else if (name === "Summary") {
-       return '\
+  } else if (name === "Summary") {
+    return '\
 <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
   <b>{{md-title}}</b>\
 </a>\
@@ -247,20 +247,20 @@ mkws.defaultTemplate = function(name) {
   <span><i>{{md-title-responsibility}}</i></span>\
 {{/if}}\
 ';
-    } else if (name === "Image") {
-       return '\
+  } else if (name === "Image") {
+    return '\
       <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
         {{#mkws-first md-thumburl}}\
-         <img src="{{this}}" alt="{{../md-title}}"/>\
+          <img src="{{this}}" alt="{{../md-title}}"/>\
         {{/mkws-first}}\
-       <br/>\
+        <br/>\
       </a>\
 ';
-    }
+  }
 
-    var s = "There is no default '" + name +"' template!";
-    alert(s);
-    return s;
+  var s = "There is no default '" + name +"' template!";
+  alert(s);
+  return s;
 };
 
 
@@ -268,280 +268,280 @@ mkws.defaultTemplate = function(name) {
 // are called from the UI using a team-name rather than implicit
 // context.
 mkws.switchView = function(tname, view) {
-    mkws.teams[tname].switchView(view);
+  mkws.teams[tname].switchView(view);
 };
 
 mkws.showDetails = function(tname, prefixRecId) {
-    mkws.teams[tname].showDetails(prefixRecId);
+  mkws.teams[tname].showDetails(prefixRecId);
 };
 
 mkws.limitTarget  = function(tname, id, name) {
-    mkws.teams[tname].limitTarget(id, name);
+  mkws.teams[tname].limitTarget(id, name);
 };
 
 mkws.limitQuery  = function(tname, field, value) {
-    mkws.teams[tname].limitQuery(field, value);
+  mkws.teams[tname].limitQuery(field, value);
 };
 
 mkws.limitCategory  = function(tname, id) {
-    mkws.teams[tname].limitCategory(id);
+  mkws.teams[tname].limitCategory(id);
 };
 
 mkws.delimitTarget = function(tname, id) {
-    mkws.teams[tname].delimitTarget(id);
+  mkws.teams[tname].delimitTarget(id);
 };
 
 mkws.delimitQuery = function(tname, field, value) {
-    mkws.teams[tname].delimitQuery(field, value);
+  mkws.teams[tname].delimitQuery(field, value);
 };
 
 mkws.showPage = function(tname, pageNum) {
-    mkws.teams[tname].showPage(pageNum);
+  mkws.teams[tname].showPage(pageNum);
 };
 
 mkws.pagerPrev = function(tname) {
-    mkws.teams[tname].pagerPrev();
+  mkws.teams[tname].pagerPrev();
 };
 
 mkws.pagerNext = function(tname) {
-    mkws.teams[tname].pagerNext();
+  mkws.teams[tname].pagerNext();
 };
 
 
 // wrapper to call team() after page load
 (function(j) {
-    var log = mkws.log;
-
-    function handleNodeWithTeam(node, callback) {
-       // First branch for DOM objects; second branch for jQuery objects
-       var classes = node.className || node.attr('class');
-       if (!classes) {
-           // For some reason, if we try to proceed when classes is
-           // undefined, we don't get an error message, but this
-           // function and its callers, up several stack level,
-           // silently return. What a crock.
-           log("handleNodeWithTeam() called on node with no classes");
-           return;
-       }
-       var list = classes.split(/\s+/)
-       var teamName, type;
-
-       for (var i = 0; i < list.length; i++) {
-           var cname = list[i];
-           if (cname.match(/^mkwsTeam_/)) {
-               teamName = cname.replace(/^mkwsTeam_/, '');
-           } else if (cname.match(/^mkws/)) {
-               type = cname.replace(/^mkws/, '');
-           }
-       }
-
-        if (!teamName) teamName = "AUTO";
-       callback.call(node, teamName, type);
+  var log = mkws.log;
+
+  function handleNodeWithTeam(node, callback) {
+    // First branch for DOM objects; second branch for jQuery objects
+    var classes = node.className || node.attr('class');
+    if (!classes) {
+      // For some reason, if we try to proceed when classes is
+      // undefined, we don't get an error message, but this
+      // function and its callers, up several stack level,
+      // silently return. What a crock.
+      log("handleNodeWithTeam() called on node with no classes");
+      return;
+    }
+    var list = classes.split(/\s+/)
+    var teamName, type;
+
+    for (var i = 0; i < list.length; i++) {
+      var cname = list[i];
+      if (cname.match(/^mkwsTeam_/)) {
+        teamName = cname.replace(/^mkwsTeam_/, '');
+      } else if (cname.match(/^mkws/)) {
+        type = cname.replace(/^mkws/, '');
+      }
     }
 
+    if (!teamName) teamName = "AUTO";
+    callback.call(node, teamName, type);
+  }
 
-    function resizePage() {
-       var threshhold = mkws.config.responsive_design_width;
-        var width = $(window).width();
-        var from, to, method;
-
-        if ((mkws.width === undefined || mkws.width > threshhold) &&
-                   width <= threshhold) {
-            from = "wide"; to = "narrow"; method = "hide";
-        } else if ((mkws.width === undefined || mkws.width <= threshhold) &&
-                   width > threshhold) {
-            from = "narrow"; to = "wide"; method = "show";
-        }
-        mkws.width = width;
-
-        if (from) {
-           log("changing from " + from + " to " + to + ": " + width);
-           for (var tname in mkws.teams) {
-                var team = mkws.teams[tname];
-                team.visitWidgets(function (t, w) {
-                    var w1 = team.widget(t + "-Container-" + from);
-                    var w2 = team.widget(t + "-Container-" + to);
-                    if (w1) {
-                        $(w1.node).hide();
-                    }
-                    if (w2) {
-                        $(w2.node).show();
-                       $(w.node).appendTo($(w2.node));
-                    }
-                });
-                team.queue("resize-" + to).publish();
-           }
-       }
-    };
 
+  function resizePage() {
+    var threshhold = mkws.config.responsive_design_width;
+    var width = $(window).width();
+    var from, to, method;
 
-    /*
-     * Run service-proxy authentication in background (after page load).
-     * The username/password is configured in the apache config file
-     * for the site.
-     */
-    function authenticateSession(auth_url, auth_domain, pp2_url) {
-       log("Run service proxy auth URL: " + auth_url);
-
-       if (!auth_domain) {
-           auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2');
-           log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
-       }
-
-       var request = new pzHttpRequest(auth_url, function(err) {
-           alert("HTTP call for authentication failed: " + err)
-           return;
-       }, auth_domain);
-
-       request.get(null, function(data) {
-           if (!$.isXMLDoc(data)) {
-               alert("service proxy auth response document is not valid XML document, give up!");
-               return;
-           }
-           var status = $(data).find("status");
-           if (status.text() != "OK") {
-               alert("service proxy auth response status: " + status.text() + ", give up!");
-               return;
-           }
-
-           log("Service proxy auth successfully done");
-           mkws.authenticated = true;
-           var authName = $(data).find("displayName").text();
-           // You'd think there would be a better way to do this:
-           var realm = $(data).find("realm:not(realmAttributes realm)").text();
-           for (var teamName in mkws.teams) {
-               mkws.teams[teamName].queue("authenticated").publish(authName, realm);
-           }
-
-           runAutoSearches();
-       });
+    if ((mkws.width === undefined || mkws.width > threshhold) &&
+        width <= threshhold) {
+      from = "wide"; to = "narrow"; method = "hide";
+    } else if ((mkws.width === undefined || mkws.width <= threshhold) &&
+               width > threshhold) {
+      from = "narrow"; to = "wide"; method = "show";
+    }
+    mkws.width = width;
+
+    if (from) {
+      log("changing from " + from + " to " + to + ": " + width);
+      for (var tname in mkws.teams) {
+        var team = mkws.teams[tname];
+        team.visitWidgets(function(t, w) {
+          var w1 = team.widget(t + "-Container-" + from);
+          var w2 = team.widget(t + "-Container-" + to);
+          if (w1) {
+            $(w1.node).hide();
+          }
+          if (w2) {
+            $(w2.node).show();
+            $(w.node).appendTo($(w2.node));
+          }
+        });
+        team.queue("resize-" + to).publish();
+      }
     }
+  };
 
 
-    function runAutoSearches() {
-       log("running auto searches");
+  /*
+   * Run service-proxy authentication in background (after page load).
+   * The username/password is configured in the apache config file
+   * for the site.
+   */
+  function authenticateSession(auth_url, auth_domain, pp2_url) {
+    log("Run service proxy auth URL: " + auth_url);
 
-       for (var teamName in mkws.teams) {
-           mkws.teams[teamName].queue("ready").publish();
-       }
+    if (!auth_domain) {
+      auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2');
+      log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
     }
 
+    var request = new pzHttpRequest(auth_url, function(err) {
+      alert("HTTP call for authentication failed: " + err)
+      return;
+    }, auth_domain);
+
+    request.get(null, function(data) {
+      if (!$.isXMLDoc(data)) {
+        alert("service proxy auth response document is not valid XML document, give up!");
+        return;
+      }
+      var status = $(data).find("status");
+      if (status.text() != "OK") {
+        alert("service proxy auth response status: " + status.text() + ", give up!");
+        return;
+      }
+
+      log("Service proxy auth successfully done");
+      mkws.authenticated = true;
+      var authName = $(data).find("displayName").text();
+      // You'd think there would be a better way to do this:
+      var realm = $(data).find("realm:not(realmAttributes realm)").text();
+      for (var teamName in mkws.teams) {
+        mkws.teams[teamName].queue("authenticated").publish(authName, realm);
+      }
+
+      runAutoSearches();
+    });
+  }
 
-    function makeWidgetsWithin(level, node) {
-        node.find('[class^="mkws"],[class*=" mkws"]').each(function() {
-            handleNodeWithTeam(this, function(tname, type) {
-                var oldHTML = this.innerHTML;
-                var myTeam = mkws.teams[tname];
-                var myWidget = widget(j, myTeam, type, this);
-                myTeam.addWidget(myWidget);
-                var newHTML = this.innerHTML;
-                if (newHTML !== oldHTML) {
-                    log("widget " + tname + ":" + type + " HTML changed: reparsing");
-                    makeWidgetsWithin(level+1, $(this));
-                }
-            });
-        });
+
+  function runAutoSearches() {
+    log("running auto searches");
+
+    for (var teamName in mkws.teams) {
+      mkws.teams[teamName].queue("ready").publish();
     }
+  }
+
+
+  function makeWidgetsWithin(level, node) {
+    node.find('[class^="mkws"],[class*=" mkws"]').each(function() {
+      handleNodeWithTeam(this, function(tname, type) {
+        var oldHTML = this.innerHTML;
+        var myTeam = mkws.teams[tname];
+        var myWidget = widget(j, myTeam, type, this);
+        myTeam.addWidget(myWidget);
+        var newHTML = this.innerHTML;
+        if (newHTML !== oldHTML) {
+          log("widget " + tname + ":" + type + " HTML changed: reparsing");
+          makeWidgetsWithin(level+1, $(this));
+        }
+      });
+    });
+  }
 
 
-    $(document).ready(function() {
-       var saved_config;
-       if (typeof mkws_config === 'undefined') {
-           log("setting empty config");
-           saved_config = {};
-       } else {
-           log("using config: " + $.toJSON(mkws_config));
-           saved_config = mkws_config;
-       }
-       mkws.setMkwsConfig(saved_config);
-
-       for (var key in mkws.config) {
-           if (mkws.config.hasOwnProperty(key)) {
-               if (key.match(/^language_/)) {
-                   var lang = key.replace(/^language_/, "");
-                   // Copy custom languages into list
-                   mkws.locale_lang[lang] = mkws.config[key];
-                   log("Added locally configured language '" + lang + "'");
-               }
-           }
-       }
-
-        var lang = mkws.getParameterByName("lang") || mkws.config.lang;
-        if (!lang || !mkws.locale_lang[lang]) {
-            mkws.config.lang = ""
-        } else {
-            mkws.config.lang = lang;
+  $(document).ready(function() {
+    var saved_config;
+    if (typeof mkws_config === 'undefined') {
+      log("setting empty config");
+      saved_config = {};
+    } else {
+      log("using config: " + $.toJSON(mkws_config));
+      saved_config = mkws_config;
+    }
+    mkws.setMkwsConfig(saved_config);
+
+    for (var key in mkws.config) {
+      if (mkws.config.hasOwnProperty(key)) {
+        if (key.match(/^language_/)) {
+          var lang = key.replace(/^language_/, "");
+          // Copy custom languages into list
+          mkws.locale_lang[lang] = mkws.config[key];
+          log("Added locally configured language '" + lang + "'");
         }
+      }
+    }
+
+    var lang = mkws.getParameterByName("lang") || mkws.config.lang;
+    if (!lang || !mkws.locale_lang[lang]) {
+      mkws.config.lang = ""
+    } else {
+      mkws.config.lang = lang;
+    }
+
+    log("Locale language: " + (mkws.config.lang ? mkws.config.lang : "none"));
+
+    if (mkws.config.query_width < 5 || mkws.config.query_width > 150) {
+      log("Reset query width: " + mkws.config.query_width);
+      mkws.config.query_width = 50;
+    }
+
+    // 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;
+      log("adjust protocol independent links: " + mkws.config.pazpar2_url);
+    }
 
-        log("Locale language: " + (mkws.config.lang ? mkws.config.lang : "none"));
-
-       if (mkws.config.query_width < 5 || mkws.config.query_width > 150) {
-           log("Reset query width: " + mkws.config.query_width);
-           mkws.config.query_width = 50;
-       }
-
-       // 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;
-           log("adjust protocol independent links: " + mkws.config.pazpar2_url);
-       }
-
-       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(resizePage);
-           // initial check after page load
-           $(document).ready(resizePage);
-       }
-
-       // Backwards compatibility: set new magic class names on any
-       // elements that have the old magic IDs.
-       var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",
-                   "Results", "Records", "Targets", "Ranking",
-                   "Termlists", "Stat", "MOTD" ];
-       for (var i = 0; i < ids.length; i++) {
-           var id = 'mkws' + ids[i];
-           var node = $('#' + id);
-           if (node.attr('id')) {
-               node.addClass(id);
-               log("added magic class to '" + node.attr('id') + "'");
-           }
-       }
-
-       // 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() {
-           handleNodeWithTeam(this, function(tname, type) {
-               if (!mkws.teams[tname]) {
-                   mkws.teams[tname] = team(j, tname);
-                   log("Made MKWS team '" + tname + "'");
-               }
-           });
-       });
-
-        makeWidgetsWithin(1, $(':root'));
-        
-       var now = $.now();
-       log("Walking MKWS nodes took " + (now-then) + " ms");
-
-        /*
-        for (var tName in mkws.teams) {
-            var myTeam = mkws.teams[tName]
-            log("TEAM '" + tName + "' = " + myTeam + " ...");
-            myTeam.visitWidgets(function(t, w) {
-                log("  has widget of type '" + t + "': " + w);
-            });
+    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(resizePage);
+      // initial check after page load
+      $(document).ready(resizePage);
+    }
+
+    // Backwards compatibility: set new magic class names on any
+    // elements that have the old magic IDs.
+    var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",
+                "Results", "Records", "Targets", "Ranking",
+                "Termlists", "Stat", "MOTD" ];
+    for (var i = 0; i < ids.length; i++) {
+      var id = 'mkws' + ids[i];
+      var node = $('#' + id);
+      if (node.attr('id')) {
+        node.addClass(id);
+        log("added magic class to '" + node.attr('id') + "'");
+      }
+    }
+
+    // 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() {
+      handleNodeWithTeam(this, function(tname, type) {
+        if (!mkws.teams[tname]) {
+          mkws.teams[tname] = team(j, tname);
+          log("Made MKWS team '" + tname + "'");
         }
-        */
-
-       if (mkws.config.use_service_proxy) {
-           authenticateSession(mkws.config.service_proxy_auth,
-                               mkws.config.service_proxy_auth_domain,
-                               mkws.config.pazpar2_url);
-       } else {
-           // raw pp2
-           runAutoSearches();
-       }
+      });
     });
+
+    makeWidgetsWithin(1, $(':root'));
+    
+    var now = $.now();
+    log("Walking MKWS nodes took " + (now-then) + " ms");
+
+    /*
+      for (var tName in mkws.teams) {
+      var myTeam = mkws.teams[tName]
+      log("TEAM '" + tName + "' = " + myTeam + " ...");
+      myTeam.visitWidgets(function(t, w) {
+      log("  has widget of type '" + t + "': " + w);
+      });
+      }
+    */
+
+    if (mkws.config.use_service_proxy) {
+      authenticateSession(mkws.config.service_proxy_auth,
+                          mkws.config.service_proxy_auth_domain,
+                          mkws.config.pazpar2_url);
+    } else {
+      // raw pp2
+      runAutoSearches();
+    }
+  });
 })(jQuery);
index 2266993..2be1bd9 100644 (file)
 // Factory function for sets of filters.
 function filterSet(team) {
-    var m_team = team;
-    var m_list = [];
-
-    var that = {};
-
-    that.toJSON = function() {
-       return $.toJSON(m_list);
-    };
-
-    that.add = function(filter) {
-       m_list.push(filter);
-    };
-
-    that.visitTargets = function(callback) {
-       for (var i in m_list) {
-           var filter = m_list[i];
-           if (filter.type === 'target') {
-               callback(filter.id, filter.name);
-           }
-       }
-    };
-
-    that.visitFields = function(callback) {
-       for (var i in m_list) {
-           var filter = m_list[i];
-           if (filter.type === 'field') {
-               callback(filter.field, filter.value);
-           }
-       }
-    };
-
-    that.visitCategories = function(callback) {
-       for (var i in m_list) {
-           var filter = m_list[i];
-           if (filter.type === 'category') {
-               callback(filter.id);
-           }
-       }
-    };
-
-    that.removeMatching = function(matchFn) {
-       var newList = [];
-       for (var i in m_list) {
-           var filter = m_list[i];
-           if (matchFn(filter)) {
-               m_team.log("removeMatching() removing filter " + $.toJSON(filter));
-           } else {
-               m_team.log("removeMatching() keeping filter " + $.toJSON(filter));
-               newList.push(filter);
-           }
-       }
-       m_list = newList;
-    };
-
-    that.targetFiltered = function(id) {
-       for (var i = 0; i < m_list.length; i++) {
-           if (m_list[i].type === 'target' ||
-               m_list[i].id === 'pz:id=' + id) {
-               return true;
-           }
-       }
-       return false;
-    };
-
-    that.pp2filter = function() {
-       var res = "";
-
-       that.visitTargets(function(id, name) {
-           if (res) res += ",";
-           if (id.match(/^[a-z:]+[=~]/)) {
-               m_team.log("filter '" + id + "' already begins with SETTING OP");
-           } else {
-               id = 'pz:id=' + id;
-           }
-           res += id;
-       });
-
-       return res;
-    };
-
-    that.pp2limit = function(initial) {
-       var res = initial || "";
-
-       that.visitFields(function(field, value) {
-           if (res) res += ",";
-           res += field + "=" + value.replace(/[\\|,]/g, '\\$&');
-       });
-       return res;
-    }
+  var m_team = team;
+  var m_list = [];
 
-    that.pp2catLimit = function() {
-       var res = "";
+  var that = {};
 
-       that.visitCategories(function(id) {
-           if (res) res += ",";
-           res += "category~" + id.replace(/[\\|,]/g, '\\$&');
-       });
-       return res;
-    }
+  that.toJSON = function() {
+    return $.toJSON(m_list);
+  };
 
-    return that;
+  that.add = function(filter) {
+    m_list.push(filter);
+  };
+
+  that.visitTargets = function(callback) {
+    for (var i in m_list) {
+      var filter = m_list[i];
+      if (filter.type === 'target') {
+        callback(filter.id, filter.name);
+      }
+    }
+  };
+
+  that.visitFields = function(callback) {
+    for (var i in m_list) {
+      var filter = m_list[i];
+      if (filter.type === 'field') {
+        callback(filter.field, filter.value);
+      }
+    }
+  };
+
+  that.visitCategories = function(callback) {
+    for (var i in m_list) {
+      var filter = m_list[i];
+      if (filter.type === 'category') {
+        callback(filter.id);
+      }
+    }
+  };
+
+  that.removeMatching = function(matchFn) {
+    var newList = [];
+    for (var i in m_list) {
+      var filter = m_list[i];
+      if (matchFn(filter)) {
+        m_team.log("removeMatching() removing filter " + $.toJSON(filter));
+      } else {
+        m_team.log("removeMatching() keeping filter " + $.toJSON(filter));
+        newList.push(filter);
+      }
+    }
+    m_list = newList;
+  };
+
+  that.targetFiltered = function(id) {
+    for (var i = 0; i < m_list.length; i++) {
+      if (m_list[i].type === 'target' ||
+          m_list[i].id === 'pz:id=' + id) {
+        return true;
+      }
+    }
+    return false;
+  };
+
+  that.pp2filter = function() {
+    var res = "";
+
+    that.visitTargets(function(id, name) {
+      if (res) res += ",";
+      if (id.match(/^[a-z:]+[=~]/)) {
+        m_team.log("filter '" + id + "' already begins with SETTING OP");
+      } else {
+        id = 'pz:id=' + id;
+      }
+      res += id;
+    });
+
+    return res;
+  };
+
+  that.pp2limit = function(initial) {
+    var res = initial || "";
+
+    that.visitFields(function(field, value) {
+      if (res) res += ",";
+      res += field + "=" + value.replace(/[\\|,]/g, '\\$&');
+    });
+    return res;
+  }
+
+  that.pp2catLimit = function() {
+    var res = "";
+
+    that.visitCategories(function(id) {
+      if (res) res += ",";
+      res += "category~" + id.replace(/[\\|,]/g, '\\$&');
+    });
+    return res;
+  }
+
+  return that;
 }
 
 
 // Factory functions for filters. These can be of several types.
 function targetFilter(id, name) {
-    return {
-        type: 'target',
-        id: id,
-        name: name
-    };
+  return {
+    type: 'target',
+    id: id,
+    name: name
+  };
 }
 
 function fieldFilter(field, value) {
-    return {
-        type: 'field',
-        field: field,
-        value: value
-    };
+  return {
+    type: 'field',
+    field: field,
+    value: value
+  };
 }
 
 function categoryFilter(id) {
-    return {
-        type: 'category',
-        id: id,
-    };
+  return {
+    type: 'category',
+    id: id,
+  };
 }
index 58c95a1..916ddba 100644 (file)
@@ -1,26 +1,26 @@
 // Handlebars helpers
 Handlebars.registerHelper('mkws-json', function(obj) {
-    return $.toJSON(obj);
+  return $.toJSON(obj);
 });
 
 
 Handlebars.registerHelper('mkws-paragraphs', function(obj) {
-    var acc = [];
-    for (var i = 0; i < obj.length; i++) {
-        acc.push('<p>', obj[i], '</p>');
-    }
-    return acc.join('');
+  var acc = [];
+  for (var i = 0; i < obj.length; i++) {
+    acc.push('<p>', obj[i], '</p>');
+  }
+  return acc.join('');
 });
 
 
 Handlebars.registerHelper('mkws-translate', function(s) {
-    return mkws.M(s);
+  return mkws.M(s);
 });
 
 
 // We need {{mkws-attr '@name'}} because Handlebars can't parse {{@name}}
 Handlebars.registerHelper('mkws-attr', function(attrName) {
-    return this[attrName];
+  return this[attrName];
 });
 
 
@@ -31,41 +31,41 @@ Handlebars.registerHelper('mkws-attr', function(attrName) {
  * array has a subelement called NAME2.
  */
 Handlebars.registerHelper('mkws-if-any', function(items, options) {
-    var having = options.hash.having;
-    for (var i in items) {
-       var item = items[i]
-       if (!having || item[having]) {
-           return options.fn(this);
-       }
+  var having = options.hash.having;
+  for (var i in items) {
+    var item = items[i]
+    if (!having || item[having]) {
+      return options.fn(this);
     }
-    return "";
+  }
+  return "";
 });
 
 
 Handlebars.registerHelper('mkws-first', function(items, options) {
-    var having = options.hash.having;
-    for (var i in items) {
-       var item = items[i]
-       if (!having || item[having]) {
-           return options.fn(item);
-       }
+  var having = options.hash.having;
+  for (var i in items) {
+    var item = items[i]
+    if (!having || item[having]) {
+      return options.fn(item);
     }
-    return "";
+  }
+  return "";
 });
 
 
 Handlebars.registerHelper('mkws-commaList', function(items, options) {
-    var out = "";
+  var out = "";
 
-    for (var i in items) {
-       if (i > 0) out += ", ";
-       out += options.fn(items[i])
-    }
+  for (var i in items) {
+    if (i > 0) out += ", ";
+    out += options.fn(items[i])
+  }
 
-    return out;
+  return out;
 });
 
 
 Handlebars.registerHelper('mkws-index1', function(obj) {
-    return obj.data.index + 1;
+  return obj.data.index + 1;
 });
index 2f79db4..90e43e4 100644 (file)
  * implement jQuery plugin $.pazpar2({})
  */
 function _mkws_jquery_plugin($) {
-    function debug (string) {
-       mkws.log("jquery.pazpar2: " + string);
+  function debug(string) {
+    mkws.log("jquery.pazpar2: " + string);
+  }
+
+  function init_popup(obj) {
+    var config = obj ? obj : {};
+
+    var height = config.height || 760;
+    var width = config.width || 880;
+    var id_button = config.id_button || "input.mkwsButton";
+    var id_popup = config.id_popup || ".mkwsPopup";
+
+    debug("popup height: " + height + ", width: " + width);
+
+    // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
+    // <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
+    if (!$.ui) {
+      debug("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
+      return;
     }
 
-    function init_popup(obj) {
-       var config = obj ? obj : {};
-
-       var height = config.height || 760;
-       var width = config.width || 880;
-       var id_button = config.id_button || "input.mkwsButton";
-       var id_popup = config.id_popup || ".mkwsPopup";
-
-       debug("popup height: " + height + ", width: " + width);
-
-       // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
-       // <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
-       if (!$.ui) {
-           debug("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
-           return;
-       }
-
-       $(id_popup).dialog({
-           closeOnEscape: true,
-           autoOpen: false,
-           height: height,
-           width: width,
-           modal: true,
-           resizable: true,
-           buttons: {
-               Cancel: function() {
-                   $(this).dialog("close");
-               }
-           },
-           close: function() { }
-       });
-
-       $(id_button)
-           .button()
-           .click(function() {
-               $(id_popup).dialog("open");
-           });
-    };
-
-    $.extend({
-
-       // service-proxy or pazpar2
-       pazpar2: function(config) {
-           if (config == null || typeof config != 'object') {
-               config = {};
-           }
-           var id_popup = config.id_popup || ".mkwsPopup";
-           id_popup = id_popup.replace(/^[#\.]/, "");
-
-           // simple layout
-           var div = '\
+    $(id_popup).dialog({
+      closeOnEscape: true,
+      autoOpen: false,
+      height: height,
+      width: width,
+      modal: true,
+      resizable: true,
+      buttons: {
+        Cancel: function() {
+          $(this).dialog("close");
+        }
+      },
+      close: function() { }
+    });
+
+    $(id_button)
+      .button()
+      .click(function() {
+        $(id_popup).dialog("open");
+      });
+  };
+
+  $.extend({
+
+    // service-proxy or pazpar2
+    pazpar2: function(config) {
+      if (config == null || typeof config != 'object') {
+        config = {};
+      }
+      var id_popup = config.id_popup || ".mkwsPopup";
+      id_popup = id_popup.replace(/^[#\.]/, "");
+
+      // simple layout
+      var div = '\
 <div class="mkwsSwitch"></div>\
 <div class="mkwsLang"></div>\
 <div class="mkwsSearch"></div>\
@@ -72,8 +72,8 @@ function _mkws_jquery_plugin($) {
 <div class="mkwsTargets"></div>\
 <div class="mkwsStat"></div>';
 
-           // new table layout
-           var table = '\
+      // new table layout
+      var table = '\
 <style type="text/css">\
   .mkwsTermlists div.facet {\
   float:left;\
@@ -96,18 +96,18 @@ function _mkws_jquery_plugin($) {
   <tr>\
     <td>\
       <div style="height:500px; overflow: auto">\
-       <div class="mkwsPager"></div>\
-       <div class="mkwsNavi"></div>\
-       <div class="mkwsRecords"></div>\
-       <div class="mkwsTargets"></div>\
-       <div class="mkwsRanking"></div>\
+        <div class="mkwsPager"></div>\
+        <div class="mkwsNavi"></div>\
+        <div class="mkwsRecords"></div>\
+        <div class="mkwsTargets"></div>\
+        <div class="mkwsRanking"></div>\
       </div>\
     </td>\
   </tr>\
   <tr>\
     <td>\
       <div style="height:300px; overflow: hidden">\
-       <div class="mkwsTermlists"></div>\
+        <div class="mkwsTermlists"></div>\
       </div>\
     </td>\
   </tr>\
@@ -118,7 +118,7 @@ function _mkws_jquery_plugin($) {
   </tr>\
 </table>';
 
-           var popup = '\
+      var popup = '\
 <div class="mkwsSearch"></div>\
 <div class="' + id_popup + '">\
   <div class="mkwsSwitch"></div>\
@@ -128,19 +128,19 @@ function _mkws_jquery_plugin($) {
   <div class="mkwsStat"></div>\
 </div>'
 
-           if (config && config.layout == 'div') {
-               debug("jquery plugin layout: div");
-               document.write(div);
-           } else if (config && config.layout == 'popup') {
-               debug("jquery plugin layout: popup with id: " + id_popup);
-               document.write(popup);
-               $(document).ready(function() { init_popup(config); });
-           } else {
-               debug("jquery plugin layout: table");
-               document.write(table);
-           }
-       }
-    });
+      if (config && config.layout == 'div') {
+        debug("jquery plugin layout: div");
+        document.write(div);
+      } else if (config && config.layout == 'popup') {
+        debug("jquery plugin layout: popup with id: " + id_popup);
+        document.write(popup);
+        $(document).ready(function() { init_popup(config); });
+      } else {
+        debug("jquery plugin layout: table");
+        document.write(table);
+      }
+    }
+  });
 };
 
 
index 3974fd9..e94d311 100644 (file)
 // pagerPrev(), pagerNext().
 //
 function team($, teamName) {
-    var that = {};
-    var m_teamName = teamName;
-    var m_submitted = false;
-    var m_query; // initially undefined
-    var m_sortOrder; // will be set below
-    var m_perpage; // will be set below
-    var m_filterSet = filterSet(that);
-    var m_totalRecordCount = 0;
-    var m_currentPage = 1;
-    var m_currentRecordId = '';
-    var m_currentRecordData = null;
-    var m_logTime = {
-       // Timestamps for logging
-       "start": $.now(),
-       "last": $.now()
-    };
-    var m_paz; // will be initialised below
-    var m_tempateText = {}; // widgets can register tempates to be compiled
-    var m_template = {}; // compiled templates, from any source
-    var m_config = mkws.objectInheritingFrom(mkws.config);
-    var m_widgets = {}; // Maps widget-type to array of widget objects
-
-    that.toString = function() { return '[Team ' + teamName + ']'; };
-
-    // Accessor methods for individual widgets: readers
-    that.name = function() { return m_teamName; };
-    that.submitted = function() { return m_submitted; };
-    that.sortOrder = function() { return m_sortOrder; };
-    that.perpage = function() { return m_perpage; };
-    that.totalRecordCount = function() { return m_totalRecordCount; };
-    that.currentPage = function() { return m_currentPage; };
-    that.currentRecordId = function() { return m_currentRecordId; };
-    that.currentRecordData = function() { return m_currentRecordData; };
-    that.filters = function() { return m_filterSet; };
-    that.config = function() { return m_config; };
-
-    // Accessor methods for individual widgets: writers
-    that.set_sortOrder = function(val) { m_sortOrder = val };
-    that.set_perpage = function(val) { m_perpage = val };
-
-
-    // The following PubSub code is modified from the jQuery manual:
-    // http://api.jquery.com/jQuery.Callbacks/
-    //
-    // Use as:
-    // team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
-    // team.queue("eventName").publish(arg1, arg2, ...);
-    //
-    var queues = {};
-    function queue(id) {
-       if (!queues[id]) {
-           var callbacks = $.Callbacks();
-           queues[id] = {
-               publish: callbacks.fire,
-               subscribe: callbacks.add,
-               unsubscribe: callbacks.remove
-           };
-       }
-       return queues[id];
-    };
-    that.queue = queue;
-
-
-    function log(s) {
-       var now = $.now();
-       var timestamp = (((now - m_logTime.start)/1000).toFixed(3) + " (+" +
-                        ((now - m_logTime.last)/1000).toFixed(3) + ") ");
-       m_logTime.last = now;
-       mkws.log(m_teamName + ": " + timestamp + s);
-       that.queue("log").publish(m_teamName, timestamp, s);
+  var that = {};
+  var m_teamName = teamName;
+  var m_submitted = false;
+  var m_query; // initially undefined
+  var m_sortOrder; // will be set below
+  var m_perpage; // will be set below
+  var m_filterSet = filterSet(that);
+  var m_totalRecordCount = 0;
+  var m_currentPage = 1;
+  var m_currentRecordId = '';
+  var m_currentRecordData = null;
+  var m_logTime = {
+    // Timestamps for logging
+    "start": $.now(),
+    "last": $.now()
+  };
+  var m_paz; // will be initialised below
+  var m_tempateText = {}; // widgets can register tempates to be compiled
+  var m_template = {}; // compiled templates, from any source
+  var m_config = mkws.objectInheritingFrom(mkws.config);
+  var m_widgets = {}; // Maps widget-type to array of widget objects
+
+  that.toString = function() { return '[Team ' + teamName + ']'; };
+
+  // Accessor methods for individual widgets: readers
+  that.name = function() { return m_teamName; };
+  that.submitted = function() { return m_submitted; };
+  that.sortOrder = function() { return m_sortOrder; };
+  that.perpage = function() { return m_perpage; };
+  that.totalRecordCount = function() { return m_totalRecordCount; };
+  that.currentPage = function() { return m_currentPage; };
+  that.currentRecordId = function() { return m_currentRecordId; };
+  that.currentRecordData = function() { return m_currentRecordData; };
+  that.filters = function() { return m_filterSet; };
+  that.config = function() { return m_config; };
+
+  // Accessor methods for individual widgets: writers
+  that.set_sortOrder = function(val) { m_sortOrder = val };
+  that.set_perpage = function(val) { m_perpage = val };
+
+
+  // The following PubSub code is modified from the jQuery manual:
+  // http://api.jquery.com/jQuery.Callbacks/
+  //
+  // Use as:
+  //    team.queue("eventName").subscribe(function(param1, param2 ...) { ... });
+  //    team.queue("eventName").publish(arg1, arg2, ...);
+  //
+  var queues = {};
+  function queue(id) {
+    if (!queues[id]) {
+      var callbacks = $.Callbacks();
+      queues[id] = {
+        publish: callbacks.fire,
+        subscribe: callbacks.add,
+        unsubscribe: callbacks.remove
+      };
     }
-    that.log = log;
-
-
-    log("start running MKWS");
-
-    m_sortOrder = m_config.sort_default;
-    m_perpage = m_config.perpage_default;
-
-    log("Create main pz2 object");
-    // create a parameters array and pass it to the pz2's constructor
-    // then register the form submit event with the pz2.search function
-    // autoInit is set to true on default
-    m_paz = new pz2({ "windowid": teamName,
-                     "pazpar2path": m_config.pazpar2_url,
-                     "usesessions" : m_config.use_service_proxy ? false : true,
-                     "oninit": onInit,
-                     "onbytarget": onBytarget,
-                     "onstat": onStat,
-                     "onterm": (m_config.facets.length ? onTerm : undefined),
-                     "onshow": onShow,
-                     "onrecord": onRecord,
-                     "showtime": 500,            //each timer (show, stat, term, bytarget) can be specified this way
-                     "termlist": m_config.facets.join(',')
-                   });
-
-    // pz2.js event handlers:
-    function onInit() {
-       log("init");
-       m_paz.stat();
-       m_paz.bytarget();
+    return queues[id];
+  };
+  that.queue = queue;
+
+
+  function log(s) {
+    var now = $.now();
+    var timestamp = (((now - m_logTime.start)/1000).toFixed(3) + " (+" +
+                     ((now - m_logTime.last)/1000).toFixed(3) + ") ");
+    m_logTime.last = now;
+    mkws.log(m_teamName + ": " + timestamp + s);
+    that.queue("log").publish(m_teamName, timestamp, s);
+  }
+  that.log = log;
+
+
+  log("start running MKWS");
+
+  m_sortOrder = m_config.sort_default;
+  m_perpage = m_config.perpage_default;
+
+  log("Create main pz2 object");
+  // create a parameters array and pass it to the pz2's constructor
+  // then register the form submit event with the pz2.search function
+  // autoInit is set to true on default
+  m_paz = new pz2({ "windowid": teamName,
+                    "pazpar2path": m_config.pazpar2_url,
+                    "usesessions" : m_config.use_service_proxy ? false : true,
+                    "oninit": onInit,
+                    "onbytarget": onBytarget,
+                    "onstat": onStat,
+                    "onterm": (m_config.facets.length ? onTerm : undefined),
+                    "onshow": onShow,
+                    "onrecord": onRecord,
+                    "showtime": 500,            //each timer (show, stat, term, bytarget) can be specified this way
+                    "termlist": m_config.facets.join(',')
+                  });
+
+  // pz2.js event handlers:
+  function onInit() {
+    log("init");
+    m_paz.stat();
+    m_paz.bytarget();
+  }
+
+  function onBytarget(data) {
+    log("target");
+    queue("targets").publish(data);
+  }
+
+  function onStat(data) {
+    queue("stat").publish(data);
+    if (parseInt(data.activeclients[0], 10) === 0)
+      queue("complete").publish(parseInt(data.hits[0], 10));
+  }
+
+  function onTerm(data) {
+    log("term");
+    queue("termlists").publish(data);
+  }
+
+  function onShow(data, teamName) {
+    log("show");
+    m_totalRecordCount = data.merged;
+    log("found " + m_totalRecordCount + " records");
+    queue("pager").publish(data);
+    queue("records").publish(data);
+  }
+
+  function onRecord(data, args, teamName) {
+    log("record");
+    // FIXME: record is async!!
+    clearTimeout(m_paz.recordTimer);
+    var detRecordDiv = findnode(recordDetailsId(data.recid[0]));
+    if (detRecordDiv.length) {
+      // in case on_show was faster to redraw element
+      return;
     }
+    m_currentRecordData = data;
+    var recordDiv = findnode('.' + recordElementId(m_currentRecordData.recid[0]));
+    var html = renderDetails(m_currentRecordData);
+    $(recordDiv).append(html);
+  }
 
-    function onBytarget(data) {
-       log("target");
-       queue("targets").publish(data);
-    }
-
-    function onStat(data) {
-       queue("stat").publish(data);
-       if (parseInt(data.activeclients[0], 10) === 0)
-           queue("complete").publish(parseInt(data.hits[0], 10));
-    }
-
-    function onTerm(data) {
-       log("term");
-       queue("termlists").publish(data);
-    }
-
-    function onShow(data, teamName) {
-       log("show");
-       m_totalRecordCount = data.merged;
-       log("found " + m_totalRecordCount + " records");
-       queue("pager").publish(data);
-       queue("records").publish(data);
-    }
-
-    function onRecord(data, args, teamName) {
-       log("record");
-       // FIXME: record is async!!
-       clearTimeout(m_paz.recordTimer);
-       var detRecordDiv = findnode(recordDetailsId(data.recid[0]));
-       if (detRecordDiv.length) {
-           // in case on_show was faster to redraw element
-           return;
-       }
-       m_currentRecordData = data;
-       var recordDiv = findnode('.' + recordElementId(m_currentRecordData.recid[0]));
-       var html = renderDetails(m_currentRecordData);
-       $(recordDiv).append(html);
-    }
-
-
-    // Used by the Records widget and onRecord()
-    function recordElementId(s) {
-       return 'mkwsRec_' + s.replace(/[^a-z0-9]/ig, '_');
-    }
-    that.recordElementId = recordElementId;
-
-    // Used by onRecord(), showDetails() and renderDetails()
-    function recordDetailsId(s) {
-       return 'mkwsDet_' + s.replace(/[^a-z0-9]/ig, '_');
-    }
-
-
-    that.targetFiltered = function(id) {
-       return m_filterSet.targetFiltered(id);
-    };
 
+  // Used by the Records widget and onRecord()
+  function recordElementId(s) {
+    return 'mkwsRec_' + s.replace(/[^a-z0-9]/ig, '_');
+  }
+  that.recordElementId = recordElementId;
 
-    that.limitTarget = function(id, name) {
-       log("limitTarget(id=" + id + ", name=" + name + ")");
-       m_filterSet.add(targetFilter(id, name));
-       if (m_query) triggerSearch();
-       return false;
-    };
+  // Used by onRecord(), showDetails() and renderDetails()
+  function recordDetailsId(s) {
+    return 'mkwsDet_' + s.replace(/[^a-z0-9]/ig, '_');
+  }
 
 
-    that.limitQuery = function(field, value) {
-       log("limitQuery(field=" + field + ", value=" + value + ")");
-       m_filterSet.add(fieldFilter(field, value));
-        if (m_query) triggerSearch();
-       return false;
-    };
+  that.targetFiltered = function(id) {
+    return m_filterSet.targetFiltered(id);
+  };
 
 
-    that.limitCategory = function(id) {
-       log("limitCategory(id=" + id + ")");
-        // Only one category filter at a time
-       m_filterSet.removeMatching(function(f) { return f.type === 'category' });
-        if (id !== '') m_filterSet.add(categoryFilter(id));
-        if (m_query) triggerSearch();
-       return false;
-    };
+  that.limitTarget = function(id, name) {
+    log("limitTarget(id=" + id + ", name=" + name + ")");
+    m_filterSet.add(targetFilter(id, name));
+    if (m_query) triggerSearch();
+    return false;
+  };
 
 
-    that.delimitTarget = function(id) {
-       log("delimitTarget(id=" + id + ")");
-       m_filterSet.removeMatching(function(f) { return f.type === 'target' });
-        if (m_query) triggerSearch();
-       return false;
-    };
+  that.limitQuery = function(field, value) {
+    log("limitQuery(field=" + field + ", value=" + value + ")");
+    m_filterSet.add(fieldFilter(field, value));
+    if (m_query) triggerSearch();
+    return false;
+  };
 
 
-    that.delimitQuery = function(field, value) {
-       log("delimitQuery(field=" + field + ", value=" + value + ")");
-       m_filterSet.removeMatching(function(f) { return f.type == 'field' &&
-                                                 field == f.field && value == f.value });
-        if (m_query) triggerSearch();
-       return false;
-    };
+  that.limitCategory = function(id) {
+    log("limitCategory(id=" + id + ")");
+    // Only one category filter at a time
+    m_filterSet.removeMatching(function(f) { return f.type === 'category' });
+    if (id !== '') m_filterSet.add(categoryFilter(id));
+    if (m_query) triggerSearch();
+    return false;
+  };
 
 
-    that.showPage = function(pageNum) {
-       m_currentPage = pageNum;
-       m_paz.showPage(m_currentPage - 1);
-    };
+  that.delimitTarget = function(id) {
+    log("delimitTarget(id=" + id + ")");
+    m_filterSet.removeMatching(function(f) { return f.type === 'target' });
+    if (m_query) triggerSearch();
+    return false;
+  };
 
 
-    that.pagerNext = function() {
-       if (m_totalRecordCount - m_perpage*m_currentPage > 0) {
-            m_paz.showNext();
-            m_currentPage++;
-       }
-    };
+  that.delimitQuery = function(field, value) {
+    log("delimitQuery(field=" + field + ", value=" + value + ")");
+    m_filterSet.removeMatching(function(f) { return f.type == 'field' &&
+                                             field == f.field && value == f.value });
+    if (m_query) triggerSearch();
+    return false;
+  };
 
 
-    that.pagerPrev = function() {
-       if (m_paz.showPrev() != false)
-            m_currentPage--;
-    };
+  that.showPage = function(pageNum) {
+    m_currentPage = pageNum;
+    m_paz.showPage(m_currentPage - 1);
+  };
 
 
-    that.reShow = function() {
-       resetPage();
-       m_paz.show(0, m_perpage, m_sortOrder);
-    };
-
-
-    function resetPage() {
-       m_currentPage = 1;
-       m_totalRecordCount = 0;
+  that.pagerNext = function() {
+    if (m_totalRecordCount - m_perpage*m_currentPage > 0) {
+      m_paz.showNext();
+      m_currentPage++;
     }
-    that.resetPage = resetPage;
-
-
-    function newSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery) {
-       log("newSearch: " + query);
+  };
 
-       if (m_config.use_service_proxy && !mkws.authenticated) {
-           alert("searching before authentication");
-           return;
-       }
 
-       m_filterSet.removeMatching(function(f) { return f.type !== 'category' });
-       triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery);
-       switchView('records'); // In case it's configured to start off as hidden
-       m_submitted = true;
-    }
-    that.newSearch = newSearch;
+  that.pagerPrev = function() {
+    if (m_paz.showPrev() != false)
+      m_currentPage--;
+  };
 
 
-    function triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery) {
-       resetPage();
-       queue("navi").publish();
+  that.reShow = function() {
+    resetPage();
+    m_paz.show(0, m_perpage, m_sortOrder);
+  };
 
-       // Continue to use previous query/sort-order unless new ones are specified
-       if (query) m_query = query;
-       if (sortOrder) m_sortOrder = sortOrder;
-       if (perpage) m_perpage = perpage;
-       if (targets) m_filterSet.add(targetFilter(targets, targets));
 
-       var pp2filter = m_filterSet.pp2filter();
-       var pp2limit = m_filterSet.pp2limit(limit);
-        var pp2catLimit = m_filterSet.pp2catLimit();
-       if (pp2catLimit) {
-            pp2filter = pp2filter ? pp2filter + "," + pp2catLimit : pp2catLimit;
-        }
+  function resetPage() {
+    m_currentPage = 1;
+    m_totalRecordCount = 0;
+  }
+  that.resetPage = resetPage;
 
-       var params = {};
-       if (pp2limit) params.limit = pp2limit;
-       if (maxrecs) params.maxrecs = maxrecs;
-       if (torusquery) {
-           if (!mkws.config.use_service_proxy)
-               alert("can't narrow search by torusquery when Service Proxy is not in use");
-           params.torusquery = torusquery;
-       }
 
-       log("triggerSearch(" + m_query + "): filters = " + m_filterSet.toJSON() + ", " +
-           "pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
+  function newSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery) {
+    log("newSearch: " + query);
 
-       m_paz.search(m_query, m_perpage, m_sortOrder, pp2filter, undefined, params);
+    if (m_config.use_service_proxy && !mkws.authenticated) {
+      alert("searching before authentication");
+      return;
     }
 
-
-    // switching view between targets and records
-    function switchView(view) {
-       var targets = widgetNode('Targets');
-       var results = widgetNode('Results') || widgetNode('Records');
-       var blanket = widgetNode('Blanket');
-       var motd    = widgetNode('MOTD');
-
-       switch(view) {
-        case 'targets':
-            if (targets) $(targets).show();
-            if (results) $(results).hide();
-            if (blanket) $(blanket).hide();
-            if (motd) $(motd).hide();
-            break;
-        case 'records':
-            if (targets) $(targets).hide();
-            if (results) $(results).show();
-            if (blanket) $(blanket).show();
-            if (motd) $(motd).hide();
-            break;
-        default:
-            alert("Unknown view '" + view + "'");
-       }
-    }
-    that.switchView = switchView;
-
-
-    // detailed record drawing
-    that.showDetails = function(recId) {
-       var oldRecordId = m_currentRecordId;
-       m_currentRecordId = recId;
-
-       // remove current detailed view if any
-       findnode('#' + recordDetailsId(oldRecordId)).remove();
-
-       // if the same clicked, just hide
-       if (recId == oldRecordId) {
-            m_currentRecordId = '';
-            m_currentRecordData = null;
-            return;
-       }
-       // request the record
-       log("showDetails() requesting record '" + recId + "'");
-       m_paz.record(recId);
-    };
-
-
-    // Finds the node of the specified class within the current team
-    function findnode(selector, teamName) {
-       teamName = teamName || m_teamName;
-
-       if (teamName === 'AUTO') {
-           selector = (selector + '.mkwsTeam_' + teamName + ',' +
-                       selector + ':not([class^="mkwsTeam"],[class*=" mkwsTeam"])');
-       } else {
-           selector = selector + '.mkwsTeam_' + teamName;
-       }
-
-       var node = $(selector);
-       //log('findnode(' + selector + ') found ' + node.length + ' nodes');
-       return node;
+    m_filterSet.removeMatching(function(f) { return f.type !== 'category' });
+    triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery);
+    switchView('records'); // In case it's configured to start off as hidden
+    m_submitted = true;
+  }
+  that.newSearch = newSearch;
+
+
+  function triggerSearch(query, sortOrder, maxrecs, perpage, limit, targets, torusquery) {
+    resetPage();
+    queue("navi").publish();
+
+    // Continue to use previous query/sort-order unless new ones are specified
+    if (query) m_query = query;
+    if (sortOrder) m_sortOrder = sortOrder;
+    if (perpage) m_perpage = perpage;
+    if (targets) m_filterSet.add(targetFilter(targets, targets));
+
+    var pp2filter = m_filterSet.pp2filter();
+    var pp2limit = m_filterSet.pp2limit(limit);
+    var pp2catLimit = m_filterSet.pp2catLimit();
+    if (pp2catLimit) {
+      pp2filter = pp2filter ? pp2filter + "," + pp2catLimit : pp2catLimit;
     }
 
-
-    function widgetNode(type) {
-        var w = that.widget(type);
-        return w ? $(w.node) : undefined;
+    var params = {};
+    if (pp2limit) params.limit = pp2limit;
+    if (maxrecs) params.maxrecs = maxrecs;
+    if (torusquery) {
+      if (!mkws.config.use_service_proxy)
+        alert("can't narrow search by torusquery when Service Proxy is not in use");
+      params.torusquery = torusquery;
     }
 
-    function renderDetails(data, marker) {
-       var template = loadTemplate("Record");
-       var details = template(data);
-       return '<div class="details mkwsTeam_' + m_teamName + '" ' +
-           'id="' + recordDetailsId(data.recid[0]) + '">' + details + '</div>';
+    log("triggerSearch(" + m_query + "): filters = " + m_filterSet.toJSON() + ", " +
+        "pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
+
+    m_paz.search(m_query, m_perpage, m_sortOrder, pp2filter, undefined, params);
+  }
+
+
+  // switching view between targets and records
+  function switchView(view) {
+    var targets = widgetNode('Targets');
+    var results = widgetNode('Results') || widgetNode('Records');
+    var blanket = widgetNode('Blanket');
+    var motd    = widgetNode('MOTD');
+
+    switch(view) {
+    case 'targets':
+      if (targets) $(targets).show();
+      if (results) $(results).hide();
+      if (blanket) $(blanket).hide();
+      if (motd) $(motd).hide();
+      break;
+    case 'records':
+      if (targets) $(targets).hide();
+      if (results) $(results).show();
+      if (blanket) $(blanket).show();
+      if (motd) $(motd).hide();
+      break;
+    default:
+      alert("Unknown view '" + view + "'");
     }
-    that.renderDetails = renderDetails;
+  }
+  that.switchView = switchView;
 
 
-    that.registerTemplate = function(name, text) {
-        m_tempateText[name] = text;
-    };
+  // detailed record drawing
+  that.showDetails = function(recId) {
+    var oldRecordId = m_currentRecordId;
+    m_currentRecordId = recId;
 
+    // remove current detailed view if any
+    findnode('#' + recordDetailsId(oldRecordId)).remove();
 
-    function loadTemplate(name) {
-       var template = m_template[name];
+    // if the same clicked, just hide
+    if (recId == oldRecordId) {
+      m_currentRecordId = '';
+      m_currentRecordData = null;
+      return;
+    }
+    // request the record
+    log("showDetails() requesting record '" + recId + "'");
+    m_paz.record(recId);
+  };
 
-       if (template === undefined) {
-           // Fall back to generic template if there is no team-specific one
-           var source;
-           var node = widgetNode("Template_" + name);
-           if (!node) {
-               node = widgetNode("Template_" + name, "ALL");
-           }
-            if (node) {
-               source = node.html();
-            }
 
-           if (!source) {
-                source = m_tempateText[name];
-            }
-           if (!source) {
-               source = mkws.defaultTemplate(name);
-           }
+  // Finds the node of the specified class within the current team
+  function findnode(selector, teamName) {
+    teamName = teamName || m_teamName;
 
-           template = Handlebars.compile(source);
-           log("compiled template '" + name + "'");
-           m_template[name] = template;
-       }
+    if (teamName === 'AUTO') {
+      selector = (selector + '.mkwsTeam_' + teamName + ',' +
+                  selector + ':not([class^="mkwsTeam"],[class*=" mkwsTeam"])');
+    } else {
+      selector = selector + '.mkwsTeam_' + teamName;
+    }
 
-       return template;
+    var node = $(selector);
+    //log('findnode(' + selector + ') found ' + node.length + ' nodes');
+    return node;
+  }
+
+
+  function widgetNode(type) {
+    var w = that.widget(type);
+    return w ? $(w.node) : undefined;
+  }
+
+  function renderDetails(data, marker) {
+    var template = loadTemplate("Record");
+    var details = template(data);
+    return '<div class="details mkwsTeam_' + m_teamName + '" ' +
+      'id="' + recordDetailsId(data.recid[0]) + '">' + details + '</div>';
+  }
+  that.renderDetails = renderDetails;
+
+
+  that.registerTemplate = function(name, text) {
+    m_tempateText[name] = text;
+  };
+
+
+  function loadTemplate(name) {
+    var template = m_template[name];
+
+    if (template === undefined) {
+      // Fall back to generic template if there is no team-specific one
+      var source;
+      var node = widgetNode("Template_" + name);
+      if (!node) {
+        node = widgetNode("Template_" + name, "ALL");
+      }
+      if (node) {
+        source = node.html();
+      }
+
+      if (!source) {
+        source = m_tempateText[name];
+      }
+      if (!source) {
+        source = mkws.defaultTemplate(name);
+      }
+
+      template = Handlebars.compile(source);
+      log("compiled template '" + name + "'");
+      m_template[name] = template;
     }
-    that.loadTemplate = loadTemplate;
 
+    return template;
+  }
+  that.loadTemplate = loadTemplate;
 
-    that.addWidget = function(w) {
-        if (m_widgets[w.type] === undefined) {
-            m_widgets[w.type] = [ w ];
-            log("Added '" + w.type + "' widget to team '" + m_teamName + "'");
-        } else {
-            m_widgets[w.type].push(w);
-            log("Added '" + w.type + "' widget #" + m_widgets[w.type].length + "' to team '" + m_teamName + "'");
-        }
+
+  that.addWidget = function(w) {
+    if (m_widgets[w.type] === undefined) {
+      m_widgets[w.type] = [ w ];
+      log("Added '" + w.type + "' widget to team '" + m_teamName + "'");
+    } else {
+      m_widgets[w.type].push(w);
+      log("Added '" + w.type + "' widget #" + m_widgets[w.type].length + "' to team '" + m_teamName + "'");
     }
+  }
 
-    that.widget = function(type) {
-        var list = m_widgets[type];
+  that.widget = function(type) {
+    var list = m_widgets[type];
 
-        if (!list)
-            return undefined;
-        if (list.length > 1) {
-            alert("widget('" + type + "') finds " + list.length + " widgets: using first");
-        }
-        return list[0];
+    if (!list)
+      return undefined;
+    if (list.length > 1) {
+      alert("widget('" + type + "') finds " + list.length + " widgets: using first");
     }
-
-    that.visitWidgets = function(callback) {
-        for (var type in m_widgets) {
-            var list = m_widgets[type];
-            for (var i = 0; i < list.length; i++) {
-                var res = callback(type, list[i]);
-                if (res !== undefined) {
-                    return res;
-                }
-            }
+    return list[0];
+  }
+
+  that.visitWidgets = function(callback) {
+    for (var type in m_widgets) {
+      var list = m_widgets[type];
+      for (var i = 0; i < list.length; i++) {
+        var res = callback(type, list[i]);
+        if (res !== undefined) {
+          return res;
         }
-        return undefined;
+      }
     }
+    return undefined;
+  }
 
 
-    return that;
+  return that;
 };
index a517e80..02cce99 100644 (file)
@@ -1,7 +1,7 @@
 mkws.registerWidgetType('Authname', function() {
-    var that = this;
+  var that = this;
 
-    this.team.queue("authenticated").subscribe(function(authName) {
-       $(that.node).html(authName);
-    });
+  this.team.queue("authenticated").subscribe(function(authName) {
+    $(that.node).html(authName);
+  });
 });
index 6460b61..e90e0ad 100644 (file)
@@ -1,29 +1,29 @@
 mkws.registerWidgetType('Builder', function() {
-    var that = this;
-    var team = this.team;
+  var that = this;
+  var team = this.team;
 
-    this.button = $('<button/>', {
-        type: 'button',
-        text: this.config.text || "Build!"
-    });
-    $(this.node).append(this.button);
-    this.button.click(function() {
-        var   query = team.widget('Query').value();
-        var    sort = team.widget('Sort').value();
-        var perpage = team.widget('Perpage').value();
+  this.button = $('<button/>', {
+    type: 'button',
+    text: this.config.text || "Build!"
+  });
+  $(this.node).append(this.button);
+  this.button.click(function() {
+    var   query = team.widget('Query').value();
+    var    sort = team.widget('Sort').value();
+    var perpage = team.widget('Perpage').value();
 
-        var html = ('<div class="mkwsRecords" ' +
-                    'autosearch="' + query + '" ' +
-                    'sort="' + sort + '" ' +
-                    'perpage="' + perpage + '"></div>');
-        var fn = that.callback || alert;
-        fn(html);
-    });
+    var html = ('<div class="mkwsRecords" ' +
+                'autosearch="' + query + '" ' +
+                'sort="' + sort + '" ' +
+                'perpage="' + perpage + '"></div>');
+    var fn = that.callback || alert;
+    fn(html);
+  });
 });
 
 mkws.registerWidgetType('ConsoleBuilder', function() {
-    mkws.promotionFunction('Builder').call(this);    
-    this.callback = function(s) {
-        console.log("Generated widget: " + s);
-    }
+  mkws.promotionFunction('Builder').call(this);    
+  this.callback = function(s) {
+    console.log("Generated widget: " + s);
+  }
 });
index 6ce09fe..aa25653 100644 (file)
@@ -1,35 +1,35 @@
 mkws.registerWidgetType('Categories', function() {
-    var that = this;
+  var that = this;
 
-    if (!this.config.use_service_proxy) {
-       alert("can't use categories widget without Service Proxy");
-       return;
-    }
+  if (!this.config.use_service_proxy) {
+    alert("can't use categories widget without Service Proxy");
+    return;
+  }
 
-    this.team.queue("authenticated").subscribe(function(authName, realm) {
-       var req = new pzHttpRequest(that.config.pazpar2_url + "?command=categories", function(err) {
-           alert("HTTP call for categories failed: " + err)
-       });
+  this.team.queue("authenticated").subscribe(function(authName, realm) {
+    var req = new pzHttpRequest(that.config.pazpar2_url + "?command=categories", function(err) {
+      alert("HTTP call for categories failed: " + err)
+    });
 
-       req.get(null, function(data) {
-           if (!$.isXMLDoc(data)) {
-               alert("categories response document is not XML");
-               return;
-           }
-           that.log("got categories: " + data);
+    req.get(null, function(data) {
+      if (!$.isXMLDoc(data)) {
+        alert("categories response document is not XML");
+        return;
+      }
+      that.log("got categories: " + data);
 
-            var text = [];
-            text.push("Select category: ");
-            text.push("<select name='mkwsCategory' " +
-                     "onchange='mkws.limitCategory(\"" + that.team.name() + "\", this.value)'>");
-            text.push("<option value=''>[All]</option>");
-            $(data).find('category').each(function() {
-                var name = $(this).find('categoryName').text();
-                var id = $(this).find('categoryId').text();
-                text.push("<option value='", id, "'>", name, "</option>");
-            });
-            text.push("</select>");
-           $(that.node).html(text.join(''));
-       });
+      var text = [];
+      text.push("Select category: ");
+      text.push("<select name='mkwsCategory' " +
+                "onchange='mkws.limitCategory(\"" + that.team.name() + "\", this.value)'>");
+      text.push("<option value=''>[All]</option>");
+      $(data).find('category').each(function() {
+        var name = $(this).find('categoryName').text();
+        var id = $(this).find('categoryId').text();
+        text.push("<option value='", id, "'>", name, "</option>");
+      });
+      text.push("</select>");
+      $(that.node).html(text.join(''));
     });
+  });
 });
index 05af4fa..828ac48 100644 (file)
@@ -1,7 +1,7 @@
 mkws.registerWidgetType('Log', function() {
-    var that = this;
+  var that = this;
 
-    this.team.queue("log").subscribe(function(teamName, timestamp, message) {
-       $(that.node).append(teamName + ": " + timestamp + message + "<br/>");
-    });
+  this.team.queue("log").subscribe(function(teamName, timestamp, message) {
+    $(that.node).append(teamName + ": " + timestamp + message + "<br/>");
+  });
 });
index 9bb08eb..6fbf5de 100644 (file)
 
 
 mkws.registerWidgetType('Targets', function() {
-    var that = this;
-    var M = mkws.M;
+  var that = this;
+  var M = mkws.M;
 
-    $(this.node).html('\
+  $(this.node).html('\
 <div class="mkwsBytarget mkwsTeam_' + this.team.name() + '">\
 No information available yet.\
 </div>');
-    $(this.node).css("display", "none");
-
-    this.team.queue("targets").subscribe(function(data) {
-       var table ='<table><thead><tr>' +
-           '<td>' + M('Target ID') + '</td>' +
-           '<td>' + M('Hits') + '</td>' +
-           '<td>' + M('Diags') + '</td>' +
-           '<td>' + M('Records') + '</td>' +
-           '<td>' + M('State') + '</td>' +
-           '</tr></thead><tbody>';
-
-       for (var i = 0; i < data.length; i++) {
-           table += "<tr><td>" + data[i].id +
-               "</td><td>" + data[i].hits +
-               "</td><td>" + data[i].diagnostic +
-               "</td><td>" + data[i].records +
-               "</td><td>" + data[i].state + "</td></tr>";
-       }
-
-       table += '</tbody></table>';
-       var subnode = $(that.node).children('.mkwsBytarget');
-       subnode.html(table);
-    });
+  $(this.node).css("display", "none");
+
+  this.team.queue("targets").subscribe(function(data) {
+    var table ='<table><thead><tr>' +
+      '<td>' + M('Target ID') + '</td>' +
+      '<td>' + M('Hits') + '</td>' +
+      '<td>' + M('Diags') + '</td>' +
+      '<td>' + M('Records') + '</td>' +
+      '<td>' + M('State') + '</td>' +
+      '</tr></thead><tbody>';
+
+    for (var i = 0; i < data.length; i++) {
+      table += "<tr><td>" + data[i].id +
+        "</td><td>" + data[i].hits +
+        "</td><td>" + data[i].diagnostic +
+        "</td><td>" + data[i].records +
+        "</td><td>" + data[i].state + "</td></tr>";
+    }
+
+    table += '</tbody></table>';
+    var subnode = $(that.node).children('.mkwsBytarget');
+    subnode.html(table);
+  });
 });
 
 
 mkws.registerWidgetType('Stat', function() {
-    var that = this;
-    var M = mkws.M;
-
-    this.team.queue("stat").subscribe(function(data) {
-       if (that.node.length === 0)  alert("huh?!");
-
-       $(that.node).html('<span class="head">' + M('Status info') + '</span>' +
-           ' -- ' +
-           '<span class="clients">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
-           ' -- ' +
-           '<span class="records">' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '</span>');
-    });
+  var that = this;
+  var M = mkws.M;
+
+  this.team.queue("stat").subscribe(function(data) {
+    if (that.node.length === 0)  alert("huh?!");
+
+    $(that.node).html('<span class="head">' + M('Status info') + '</span>' +
+                      ' -- ' +
+                      '<span class="clients">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
+                      ' -- ' +
+                      '<span class="records">' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '</span>');
+  });
 });
 
 
 mkws.registerWidgetType('Pager', function() {
-    var that = this;
-    var M = mkws.M;
-
-    this.team.queue("pager").subscribe(function(data) {
-       $(that.node).html(drawPager(data))
-
-       function drawPager(data) {
-           var teamName = that.team.name();
-           var s = '<div style="float: right">' + M('Displaying') + ': '
-               + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
-               ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
-               + data.total + ')</div>';
-
-           //client indexes pages from 1 but pz2 from 0
-           var onsides = 6;
-           var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage());
-           var currentPage = that.team.currentPage();
-
-           var firstClkbl = (currentPage - onsides > 0)
-               ? currentPage - onsides
-               : 1;
-
-           var lastClkbl = firstClkbl + 2*onsides < pages
-               ? firstClkbl + 2*onsides
-               : pages;
-
-           var prev = '<span class="mkwsPrev">&#60;&#60; ' + M('Prev') + '</span> | ';
-           if (currentPage > 1)
-               prev = '<a href="#" class="mkwsPrev" onclick="mkws.pagerPrev(\'' + teamName + '\');">'
-               +'&#60;&#60; ' + M('Prev') + '</a> | ';
-
-           var middle = '';
-           for(var i = firstClkbl; i <= lastClkbl; i++) {
-               var numLabel = i;
-               if(i == currentPage)
-                   numLabel = '<span class="mkwsSelected">' + i + '</span>';
-
-               middle += '<a href="#" onclick="mkws.showPage(\'' + teamName + '\', ' + i + ')"> '
-                   + numLabel + ' </a>';
-           }
-
-           var next = ' | <span class="mkwsNext">' + M('Next') + ' &#62;&#62;</span>';
-           if (pages - currentPage > 0)
-               next = ' | <a href="#" class="mkwsNext" onclick="mkws.pagerNext(\'' + teamName + '\')">'
-               + M('Next') + ' &#62;&#62;</a>';
-
-           var predots = '';
-           if (firstClkbl > 1)
-               predots = '...';
-
-           var postdots = '';
-           if (lastClkbl < pages)
-               postdots = '...';
-
-           s += '<div style="float: clear">'
-               + prev + predots + middle + postdots + next + '</div>';
-
-           return s;
-       }
-    });
+  var that = this;
+  var M = mkws.M;
+
+  this.team.queue("pager").subscribe(function(data) {
+    $(that.node).html(drawPager(data))
+
+    function drawPager(data) {
+      var teamName = that.team.name();
+      var s = '<div style="float: right">' + M('Displaying') + ': '
+        + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
+        ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
+        + data.total + ')</div>';
+
+      //client indexes pages from 1 but pz2 from 0
+      var onsides = 6;
+      var pages = Math.ceil(that.team.totalRecordCount() / that.team.perpage());
+      var currentPage = that.team.currentPage();
+
+      var firstClkbl = (currentPage - onsides > 0)
+        ? currentPage - onsides
+        : 1;
+
+      var lastClkbl = firstClkbl + 2*onsides < pages
+        ? firstClkbl + 2*onsides
+        : pages;
+
+      var prev = '<span class="mkwsPrev">&#60;&#60; ' + M('Prev') + '</span> | ';
+      if (currentPage > 1)
+        prev = '<a href="#" class="mkwsPrev" onclick="mkws.pagerPrev(\'' + teamName + '\');">'
+        +'&#60;&#60; ' + M('Prev') + '</a> | ';
+
+      var middle = '';
+      for(var i = firstClkbl; i <= lastClkbl; i++) {
+        var numLabel = i;
+        if(i == currentPage)
+          numLabel = '<span class="mkwsSelected">' + i + '</span>';
+
+        middle += '<a href="#" onclick="mkws.showPage(\'' + teamName + '\', ' + i + ')"> '
+          + numLabel + ' </a>';
+      }
+
+      var next = ' | <span class="mkwsNext">' + M('Next') + ' &#62;&#62;</span>';
+      if (pages - currentPage > 0)
+        next = ' | <a href="#" class="mkwsNext" onclick="mkws.pagerNext(\'' + teamName + '\')">'
+        + M('Next') + ' &#62;&#62;</a>';
+
+      var predots = '';
+      if (firstClkbl > 1)
+        predots = '...';
+
+      var postdots = '';
+      if (lastClkbl < pages)
+        postdots = '...';
+
+      s += '<div style="float: clear">'
+        + prev + predots + middle + postdots + next + '</div>';
+
+      return s;
+    }
+  });
 });
 
 
 mkws.registerWidgetType('Records', function() {
-    var that = this;
-    var team = this.team;
-
-    this.team.queue("records").subscribe(function(data) {
-       var html = [];
-       for (var i = 0; i < data.hits.length; i++) {
-           var hit = data.hits[i];
-            that.team.queue("record").publish(hit);
-           var divId = team.recordElementId(hit.recid[0]);
-           html.push('<div class="record mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
-           // ### At some point, we may be able to move the
-           // m_currentRecordId and m_currentRecordData members
-           // from the team object into this widget.
-           if (hit.recid == team.currentRecordId()) {
-               if (team.currentRecordData())
-                   html.push(team.renderDetails(team.currentRecordData()));
-           }
-       }
-       $(that.node).html(html.join(''));
-
-       function renderSummary(hit) {
-           var template = team.loadTemplate(that.config.template || "Summary");
-           hit._id = team.recordElementId(hit.recid[0]);
-           hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
-           return template(hit);
-       }
-    });
+  var that = this;
+  var team = this.team;
+
+  this.team.queue("records").subscribe(function(data) {
+    var html = [];
+    for (var i = 0; i < data.hits.length; i++) {
+      var hit = data.hits[i];
+      that.team.queue("record").publish(hit);
+      var divId = team.recordElementId(hit.recid[0]);
+      html.push('<div class="record mkwsTeam_' + team.name() + ' ' + divId + '">', renderSummary(hit), '</div>');
+      // ### At some point, we may be able to move the
+      // m_currentRecordId and m_currentRecordData members
+      // from the team object into this widget.
+      if (hit.recid == team.currentRecordId()) {
+        if (team.currentRecordData())
+          html.push(team.renderDetails(team.currentRecordData()));
+      }
+    }
+    $(that.node).html(html.join(''));
 
-    widget.autosearch(that);
+    function renderSummary(hit) {
+      var template = team.loadTemplate(that.config.template || "Summary");
+      hit._id = team.recordElementId(hit.recid[0]);
+      hit._onclick = "mkws.showDetails('" + team.name() + "', '" + hit.recid[0] + "');return false;"
+      return template(hit);
+    }
+  });
+
+  widget.autosearch(that);
 });
 
 
 mkws.registerWidgetType('Navi', function() {
-    var that = this;
-    var teamName = this.team.name();
-    var M = mkws.M;
-
-    this.team.queue("navi").subscribe(function() {
-       var filters = that.team.filters();
-       var text = "";
-
-       filters.visitTargets(function(id, name) {
-           if (text) text += " | ";
-           text += M('source') + ': <a class="crossout" href="#" onclick="mkws.delimitTarget(\'' + teamName +
-               "', '" + id + "'" + ');return false;">' + name + '</a>';
-       });
-
-       filters.visitFields(function(field, value) {
-           if (text) text += " | ";
-           text += M(field) + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(\'' + teamName +
-               "', '" + field + "', '" + value + "'" +
-               ');return false;">' + value + '</a>';
-       });
-
-       $(that.node).html(text);
+  var that = this;
+  var teamName = this.team.name();
+  var M = mkws.M;
+
+  this.team.queue("navi").subscribe(function() {
+    var filters = that.team.filters();
+    var text = "";
+
+    filters.visitTargets(function(id, name) {
+      if (text) text += " | ";
+      text += M('source') + ': <a class="crossout" href="#" onclick="mkws.delimitTarget(\'' + teamName +
+        "', '" + id + "'" + ');return false;">' + name + '</a>';
+    });
+
+    filters.visitFields(function(field, value) {
+      if (text) text += " | ";
+      text += M(field) + ': <a class="crossout" href="#" onclick="mkws.delimitQuery(\'' + teamName +
+        "', '" + field + "', '" + value + "'" +
+        ');return false;">' + value + '</a>';
     });
+
+    $(that.node).html(text);
+  });
 });
 
 
@@ -181,55 +181,55 @@ mkws.registerWidgetType('Navi', function() {
 // anything, since they produce events rather than consuming them.
 //
 mkws.registerWidgetType('Sort', function() {
-    var that = this;
-
-    $(this.node).change(function() {
-       that.team.set_sortOrder($(that.node).val());
-       if (that.team.submitted()) {
-           that.team.reShow();
-       }
-       return false;
-    });
+  var that = this;
+
+  $(this.node).change(function() {
+    that.team.set_sortOrder($(that.node).val());
+    if (that.team.submitted()) {
+      that.team.reShow();
+    }
+    return false;
+  });
 });
 
 
 mkws.registerWidgetType('Perpage', function() {
-    var that = this;
-
-    $(this.node).change(function() {
-       that.team.set_perpage($(that.node).val());
-       if (that.team.submitted()) {
-           that.team.reShow();
-       }
-       return false;
-    });
+  var that = this;
+
+  $(this.node).change(function() {
+    that.team.set_perpage($(that.node).val());
+    if (that.team.submitted()) {
+      that.team.reShow();
+    }
+    return false;
+  });
 });
 
 
 mkws.registerWidgetType('Done', function() {
-    var that = this;
+  var that = this;
 
-    this.team.queue("complete").subscribe(function(n) {
-       $(that.node).html("Search complete: found " + n + " records");
-    });
+  this.team.queue("complete").subscribe(function(n) {
+    $(that.node).html("Search complete: found " + n + " records");
+  });
 });
 
 
 mkws.registerWidgetType('Switch', function() {
-    var tname = this.team.name();
-    $(this.node).html('\
+  var tname = this.team.name();
+  $(this.node).html('\
 <a href="#" onclick="mkws.switchView(\'' + tname + '\', \'records\')">Records</a><span> \
 | \
 </span><a href="#" onclick="mkws.switchView(\'' + tname + '\', \'targets\')">Targets</a>');
-    widget.hideWhenNarrow(this);
+  widget.hideWhenNarrow(this);
 });
 
 
 mkws.registerWidgetType('Search', function() {
-    var tname = this.team.name();
-    var M = mkws.M;
+  var tname = this.team.name();
+  var M = mkws.M;
 
-    $(this.node).html('\
+  $(this.node).html('\
 <form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
   <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + this.config.query_width + '" />\
   <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
@@ -238,19 +238,19 @@ mkws.registerWidgetType('Search', function() {
 
 
 mkws.registerWidgetType('SearchForm', function() {
-    var team = this.team;    
-    $(this.node).submit(function() {
-       var val = team.widget('Query').value();
-       team.newSearch(val);
-       return false;
-    });
+  var team = this.team;    
+  $(this.node).submit(function() {
+    var val = team.widget('Query').value();
+    team.newSearch(val);
+    return false;
+  });
 });
 
 
 mkws.registerWidgetType('Results', function() {
-    var tname = this.team.name();
+  var tname = this.team.name();
 
-    $(this.node).html('\
+  $(this.node).html('\
 <table width="100%" border="0" cellpadding="6" cellspacing="0">\
   <tr>\
     <td class="mkwsTermlists-Container-wide mkwsTeam_' + tname + '" width="250" valign="top">\
@@ -270,143 +270,143 @@ mkws.registerWidgetType('Results', function() {
   </tr>\
 </table>');
 
-    widget.autosearch(this);
+  widget.autosearch(this);
 });
 
 
 mkws.registerWidgetType('Ranking', function() {
-    var tname = this.team.name();
-    var that = this;
-    var M = mkws.M;
-
-    var s = '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + tname + '" action="" >';
-    if (this.config.show_sort) {
-       s +=  M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
+  var tname = this.team.name();
+  var that = this;
+  var M = mkws.M;
+
+  var s = '<form name="mkwsSelect" class="mkwsSelect mkwsTeam_' + tname + '" action="" >';
+  if (this.config.show_sort) {
+    s +=  M('Sort by') + ' ' + mkwsHtmlSort() + ' ';
+  }
+  if (this.config.show_perpage) {
+    s += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
+  }
+  s += '</form>';
+
+  $(this.node).html(s);
+
+
+  function mkwsHtmlSort() {
+    var order = that.team.sortOrder();
+
+    that.log("HTML sort, sortOrder = '" + order + "'");
+    var sort_html = '<select class="mkwsSort mkwsTeam_' + tname + '">';
+
+    for(var i = 0; i < that.config.sort_options.length; i++) {
+      var opt = that.config.sort_options[i];
+      var key = opt[0];
+      var val = opt.length == 1 ? opt[0] : opt[1];
+
+      sort_html += '<option value="' + key + '"';
+      if (order == key || order == val) {
+        sort_html += ' selected="selected"';
+      }
+      sort_html += '>' + M(val) + '</option>';
     }
-    if (this.config.show_perpage) {
-       s += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.';
-    }
-    s += '</form>';
-
-    $(this.node).html(s);
+    sort_html += '</select>';
 
+    return sort_html;
+  }
 
-    function mkwsHtmlSort() {
-        var order = that.team.sortOrder();
+  function mkwsHtmlPerpage() {
+    var perpage = that.team.perpage();
 
-       that.log("HTML sort, sortOrder = '" + order + "'");
-       var sort_html = '<select class="mkwsSort mkwsTeam_' + tname + '">';
+    that.log("HTML perpage, perpage = " + perpage);
+    var perpage_html = '<select class="mkwsPerpage mkwsTeam_' + tname + '">';
 
-       for(var i = 0; i < that.config.sort_options.length; i++) {
-           var opt = that.config.sort_options[i];
-           var key = opt[0];
-           var val = opt.length == 1 ? opt[0] : opt[1];
+    for(var i = 0; i < that.config.perpage_options.length; i++) {
+      var key = that.config.perpage_options[i];
 
-           sort_html += '<option value="' + key + '"';
-           if (order == key || order == val) {
-               sort_html += ' selected="selected"';
-           }
-           sort_html += '>' + M(val) + '</option>';
-       }
-       sort_html += '</select>';
-
-       return sort_html;
+      perpage_html += '<option value="' + key + '"';
+      if (key == perpage) {
+        perpage_html += ' selected="selected"';
+      }
+      perpage_html += '>' + key + '</option>';
     }
+    perpage_html += '</select>';
 
-    function mkwsHtmlPerpage() {
-        var perpage = that.team.perpage();
-
-       that.log("HTML perpage, perpage = " + perpage);
-       var perpage_html = '<select class="mkwsPerpage mkwsTeam_' + tname + '">';
-
-       for(var i = 0; i < that.config.perpage_options.length; i++) {
-           var key = that.config.perpage_options[i];
-
-           perpage_html += '<option value="' + key + '"';
-           if (key == perpage) {
-               perpage_html += ' selected="selected"';
-           }
-           perpage_html += '>' + key + '</option>';
-       }
-       perpage_html += '</select>';
-
-       return perpage_html;
-    }
+    return perpage_html;
+  }
 });
 
 
 mkws.registerWidgetType('Lang', function() {
-    // dynamic URL or static page? /path/foo?query=test
-    /* create locale language menu */
-    if (!this.config.show_lang) return;
-
-    var lang_default = "en";
-    var lang = this.config.lang || lang_default;
-    var list = [];
-
-    /* display a list of configured languages, or all */
-    var lang_options = this.config.lang_options || [];
-    var toBeIncluded = {};
-    for (var i = 0; i < lang_options.length; i++) {
-       toBeIncluded[lang_options[i]] = true;
-    }
-
-    for (var k in mkws.locale_lang) {
-       if (toBeIncluded[k] || lang_options.length == 0)
-           list.push(k);
+  // dynamic URL or static page? /path/foo?query=test
+  /* create locale language menu */
+  if (!this.config.show_lang) return;
+
+  var lang_default = "en";
+  var lang = this.config.lang || lang_default;
+  var list = [];
+
+  /* display a list of configured languages, or all */
+  var lang_options = this.config.lang_options || [];
+  var toBeIncluded = {};
+  for (var i = 0; i < lang_options.length; i++) {
+    toBeIncluded[lang_options[i]] = true;
+  }
+
+  for (var k in mkws.locale_lang) {
+    if (toBeIncluded[k] || lang_options.length == 0)
+      list.push(k);
+  }
+
+  // add english link
+  if (lang_options.length == 0 || toBeIncluded[lang_default])
+    list.push(lang_default);
+
+  this.log("Language menu for: " + list.join(", "));
+
+  /* the HTML part */
+  var data = "";
+  for (var i = 0; i < list.length; i++) {
+    var l = list[i];
+    if (data)
+      data += ' | ';
+
+    if (lang == l) {
+      data += ' <span>' + l + '</span> ';
+    } else {
+      data += ' <a href="' + lang_url(l) + '">' + l + '</a> '
     }
+  }
 
-    // add english link
-    if (lang_options.length == 0 || toBeIncluded[lang_default])
-        list.push(lang_default);
+  $(this.node).html(data);
+  widget.hideWhenNarrow(this);
 
-    this.log("Language menu for: " + list.join(", "));
 
-    /* the HTML part */
-    var data = "";
-    for (var i = 0; i < list.length; i++) {
-       var l = list[i];
-       if (data)
-           data += ' | ';
-
-       if (lang == l) {
-           data += ' <span>' + l + '</span> ';
-       } else {
-           data += ' <a href="' + lang_url(l) + '">' + l + '</a> '
-       }
+  // set or re-set "lang" URL parameter
+  function lang_url(lang) {
+    var query = location.search;
+    // no query parameters? done
+    if (!query) {
+      return "?lang=" + lang;
     }
 
-    $(this.node).html(data);
-    widget.hideWhenNarrow(this);
-
-
-    // set or re-set "lang" URL parameter
-    function lang_url(lang) {
-       var query = location.search;
-       // no query parameters? done
-       if (!query) {
-           return "?lang=" + lang;
-       }
-
-       // parameter does not exist
-       if (!query.match(/[\?&]lang=/)) {
-            return query + "&lang=" + lang;
-        }
-
-       // replace existing parameter
-       query = query.replace(/\?lang=([^&#;]*)/, "?lang=" + lang);
-       query = query.replace(/\&lang=([^&#;]*)/, "&lang=" + lang);
-       return query;
+    // parameter does not exist
+    if (!query.match(/[\?&]lang=/)) {
+      return query + "&lang=" + lang;
     }
+
+    // replace existing parameter
+    query = query.replace(/\?lang=([^&#;]*)/, "?lang=" + lang);
+    query = query.replace(/\&lang=([^&#;]*)/, "&lang=" + lang);
+    return query;
+  }
 });
 
 
 mkws.registerWidgetType('MOTD', function() {
-    var container = this.team.widget('MOTDContainer');
-    if (container) {
-       // Move the MOTD from the provided element down into the container
-       $(this.node).appendTo(container.node);
-    }
+  var container = this.team.widget('MOTDContainer');
+  if (container) {
+    // Move the MOTD from the provided element down into the container
+    $(this.node).appendTo(container.node);
+  }
 });
 
 
@@ -421,7 +421,7 @@ mkws.registerWidgetType('Button', function() {});
 mkws.registerWidgetType('Popup', function() {});
 
 // Not sure whether the following should have functionality:
-// Select              HTMLFormElement
-// *-Container-wide    HTMLTableCellElement
-// *-Container-narrow  HTMLDivElement
-// Bytarget            HTMLDivElement
+// Select               HTMLFormElement
+// *-Container-wide     HTMLTableCellElement
+// *-Container-narrow   HTMLDivElement
+// Bytarget             HTMLDivElement
index f1167de..106c8a3 100644 (file)
@@ -1,24 +1,24 @@
 mkws.registerWidgetType('Record', function() {
-    mkws.promotionFunction('Records').call(this);
-    if (!this.config.maxrecs) this.config.maxrecs = 1;
+  mkws.promotionFunction('Records').call(this);
+  if (!this.config.maxrecs) this.config.maxrecs = 1;
 });
 
 mkws.registerWidgetType('Image', function() {
-    mkws.promotionFunction('Record').call(this);
-    if (!this.config.template) this.config.template = 'Image';
+  mkws.promotionFunction('Record').call(this);
+  if (!this.config.template) this.config.template = 'Image';
 });
 
 mkws.registerWidgetType('GoogleImage', function() {
-    mkws.promotionFunction('Image').call(this);
-    if (!this.config.target) this.config.target = 'Google_Images';
+  mkws.promotionFunction('Image').call(this);
+  if (!this.config.target) this.config.target = 'Google_Images';
 });
 
 mkws.registerWidgetType('Lolcat', function() {
-    mkws.promotionFunction('GoogleImage').call(this);
-    if (!this.config.autosearch) this.config.autosearch = 'kitteh';
+  mkws.promotionFunction('GoogleImage').call(this);
+  if (!this.config.autosearch) this.config.autosearch = 'kitteh';
 });
 
 mkws.registerWidgetType('Coverart', function() {
-    mkws.promotionFunction('Image').call(this);
-    if (!this.config.target) this.config.target = 'AmazonBooks';
+  mkws.promotionFunction('Image').call(this);
+  if (!this.config.target) this.config.target = 'AmazonBooks';
 });
index 3ea68f5..b62da04 100644 (file)
@@ -1,68 +1,68 @@
 mkws.registerWidgetType('Termlists', function() {
-    var that = this;
+  var that = this;
 
-    // Initially hide the termlists; display when we get results
-    $(document).ready(function() {
-        $(that.node).hide();
-    });
-    this.team.queue("termlists").subscribe(function(data) {
-       $(that.node).show();
-    });
+  // Initially hide the termlists; display when we get results
+  $(document).ready(function() {
+    $(that.node).hide();
+  });
+  this.team.queue("termlists").subscribe(function(data) {
+    $(that.node).show();
+  });
 
-    var acc = [];
-    var facets = this.config.facets;
-    acc.push('<div class="title">' + mkws.M('Termlists') + '</div>');
-    for (var i = 0; i < facets.length; i++) {
-       acc.push('<div class="mkwsFacet mkwsTeam_', this.team.name(), '" data-mkws-facet="', facets[i], '">', '</div>');
-    }
-    $(this.node).html(acc.join(''));
+  var acc = [];
+  var facets = this.config.facets;
+  acc.push('<div class="title">' + mkws.M('Termlists') + '</div>');
+  for (var i = 0; i < facets.length; i++) {
+    acc.push('<div class="mkwsFacet mkwsTeam_', this.team.name(), '" data-mkws-facet="', facets[i], '">', '</div>');
+  }
+  $(this.node).html(acc.join(''));
 
-    widget.autosearch(this);
+  widget.autosearch(this);
 });
 
 
 mkws.registerWidgetType('Facet', function() {
-    var facetConfig = {
-       xtargets: [ "Sources",  16, false ],
-       subject:  [ "Subjects", 10, true ],
-       author:   [ "Authors",  10, true ]
-    }
+  var facetConfig = {
+    xtargets: [ "Sources",  16, false ],
+    subject:  [ "Subjects", 10, true ],
+    author:   [ "Authors",  10, true ]
+  }
 
-    var that = this;
-    var name = that.config.facet;
-    var ref = facetConfig[name] || alert("no facet definition for '" + name + "'");
-    var caption = ref[0];
-    var max = ref[1];
-    var pzIndex = ref[2] ? name : null;
+  var that = this;
+  var name = that.config.facet;
+  var ref = facetConfig[name] || alert("no facet definition for '" + name + "'");
+  var caption = ref[0];
+  var max = ref[1];
+  var pzIndex = ref[2] ? name : null;
 
-    that.toString = function() {
-       return '[Widget ' + that.team.name() + ':' + that.type + '(' + name + ')]';
-    };
+  that.toString = function() {
+    return '[Widget ' + that.team.name() + ':' + that.type + '(' + name + ')]';
+  };
 
-    that.team.queue("termlists").subscribe(function(data) {
-       data = data[name];
+  that.team.queue("termlists").subscribe(function(data) {
+    data = data[name];
 
-       var teamName = that.team.name();
-       var acc = [];
-       acc.push('<div class="termtitle">' + mkws.M(caption) + '</div>');
-       for (var i = 0; i < data.length && i < max; i++) {
-           acc.push('<div class="term">');
-           acc.push('<a href="#" ');
-           var action = '';
-           if (!pzIndex) {
-               // Special case: target selection
-               acc.push('target_id='+data[i].id+' ');
-               if (!that.team.targetFiltered(data[i].id)) {
-                   action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
-               }
-           } else {
-               action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
-           }
-           acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
-                    + ' <span>' + data[i].freq + '</span>');
-           acc.push('</div>');
-       }
+    var teamName = that.team.name();
+    var acc = [];
+    acc.push('<div class="termtitle">' + mkws.M(caption) + '</div>');
+    for (var i = 0; i < data.length && i < max; i++) {
+      acc.push('<div class="term">');
+      acc.push('<a href="#" ');
+      var action = '';
+      if (!pzIndex) {
+        // Special case: target selection
+        acc.push('target_id='+data[i].id+' ');
+        if (!that.team.targetFiltered(data[i].id)) {
+          action = 'mkws.limitTarget(\'' + teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
+        }
+      } else {
+        action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
+      }
+      acc.push('onclick="' + action + ';return false;">' + data[i].name + '</a>'
+               + ' <span>' + data[i].freq + '</span>');
+      acc.push('</div>');
+    }
 
-       $(that.node).html(acc.join(''));
-    });
+    $(that.node).html(acc.join(''));
+  });
 });
index faee22d..6bb9aaa 100644 (file)
 // Factory function for widget objects.
 function widget($, team, type, node) {
-    // Static register of attributes that do not contribute to config
-    var ignoreAttrs = {
-       id:1, 'class':1, style:1, name:1, action:1, type:1, size:1,
-       value:1, width:1, valign:1
-    };
-
-    var that = {
-       team: team,
-       type: type,
-       node: node,
-       config: mkws.objectInheritingFrom(team.config())
-    };
-
-    function log(s) {
-       team.log(s);
+  // Static register of attributes that do not contribute to config
+  var ignoreAttrs = {
+    id:1, 'class':1, style:1, name:1, action:1, type:1, size:1,
+    value:1, width:1, valign:1
+  };
+
+  var that = {
+    team: team,
+    type: type,
+    node: node,
+    config: mkws.objectInheritingFrom(team.config())
+  };
+
+  function log(s) {
+    team.log(s);
+  }
+  that.log = log;
+
+  that.toString = function() {
+    return '[Widget ' + team.name() + ':' + type + ']';
+  };
+
+  that.value = function() {
+    return node.value;
+  }
+
+  for (var i = 0; i < node.attributes.length; i++) {
+    var a = node.attributes[i];
+    if (a.name === 'data-mkws-config') {
+      // Treat as a JSON fragment configuring just this widget
+      log(node + ": parsing config fragment '" + a.value + "'");
+      var data;
+      try {
+        data = $.parseJSON(a.value);
+        for (var key in data) {
+          log(node + ": adding config element " + key + "='" + data[key] + "'");
+          that.config[key] = data[key];
+        }
+      } catch (err) {
+        alert("Can't parse " + node + " data-mkws-config as JSON: " + a.value);
+      }
+    } else if (a.name.match (/^data-mkws-/)) {
+      var name = a.name.replace(/^data-mkws-/, '')
+      that.config[name] = a.value;
+      log(node + ": set data-mkws attribute " + name + "='" + a.value + "'");
+    } else if (!ignoreAttrs[a.name]) {
+      that.config[a.name] = a.value;
+      log(node + ": set regular attribute " + a.name + "='" + a.value + "'");
     }
-    that.log = log;
+  }
 
-    that.toString = function() {
-       return '[Widget ' + team.name() + ':' + type + ']';
-    };
+  var fn = mkws.promotionFunction(type);
+  if (fn) {
+    fn.call(that);
+    log("made " + type + " widget(node=" + node + ")");
+  } else {
+    log("made UNPROMOTED widget(type=" + type + ", node=" + node + ")");
+  }
 
-    that.value = function() {
-        return node.value;
-    }
-
-    for (var i = 0; i < node.attributes.length; i++) {
-       var a = node.attributes[i];
-       if (a.name === 'data-mkws-config') {
-           // Treat as a JSON fragment configuring just this widget
-           log(node + ": parsing config fragment '" + a.value + "'");
-           var data;
-           try {
-               data = $.parseJSON(a.value);
-               for (var key in data) {
-                   log(node + ": adding config element " + key + "='" + data[key] + "'");
-                   that.config[key] = data[key];
-               }
-           } catch (err) {
-               alert("Can't parse " + node + " data-mkws-config as JSON: " + a.value);
-           }
-       } else if (a.name.match (/^data-mkws-/)) {
-           var name = a.name.replace(/^data-mkws-/, '')
-           that.config[name] = a.value;
-           log(node + ": set data-mkws attribute " + name + "='" + a.value + "'");
-       } else if (!ignoreAttrs[a.name]) {
-           that.config[a.name] = a.value;
-           log(node + ": set regular attribute " + a.name + "='" + a.value + "'");
-       }
-    }
-
-    var fn = mkws.promotionFunction(type);
-    if (fn) {
-       fn.call(that);
-       log("made " + type + " widget(node=" + node + ")");
-    } else {
-       log("made UNPROMOTED widget(type=" + type + ", node=" + node + ")");
-    }
-
-    return that;
+  return that;
 }
 
 
 // Utility function for use by all widgets that can invoke autosearch.
 widget.autosearch = function(widget) {
-    widget.team.queue("ready").subscribe(function() {
-       var query = widget.config.autosearch;
-       if (query) {
-           if (query.match(/^!param!/)) {
-               var param = query.replace(/^!param!/, '');
-               query = mkws.getParameterByName(param);
-               widget.log("obtained query '" + query + "' from param '" + param + "'");
-               if (!query) {
-                   alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter");
-               }
-           } else if (query.match(/^!path!/)) {
-               var index = query.replace(/^!path!/, '');
-               var path = window.location.pathname.split('/');
-               query = path[path.length - index];
-               widget.log("obtained query '" + query + "' from path-component '" + index + "'");
-               if (!query) {
-                   alert("This page has a MasterKey widget that needs a query specified by the path-component " + index);
-               }
-            } else if (query.match(/^!var!/)) {
-               var name = query.replace(/^!var!/, '');
-               query = window[name]; // It's ridiculous that this works
-               widget.log("obtained query '" + query + "' from variable '" + name + "'");
-               if (!query) {
-                   alert("This page has a MasterKey widget that needs a query specified by the '" + name + "' variable");
-               }
-           }
-
-           var sortOrder = widget.config.sort;
-           var maxrecs = widget.config.maxrecs;
-           var perpage = widget.config.perpage;
-           var limit = widget.config.limit;
-           var targets = widget.config.targets;
-           var targetfilter = widget.config.targetfilter;
-           var target = widget.config.target;
-           if (target) targetfilter = 'udb=="' + target + '"';
-
-           var s = "running auto search: '" + query + "'";
-           if (sortOrder) s += " sorted by '" + sortOrder + "'";
-           if (maxrecs) s += " restricted to " + maxrecs + " records";
-           if (perpage) s += " with " + perpage + " per page";
-           if (limit) s += " limited by '" + limit + "'";
-           if (targets) s += " in targets '" + targets + "'";
-           if (targetfilter) s += " constrained by targetfilter '" + targetfilter + "'";
-           widget.log(s);
-
-           widget.team.newSearch(query, sortOrder, maxrecs, perpage, limit, targets, targetfilter);
-       }
-    });
+  widget.team.queue("ready").subscribe(function() {
+    var query = widget.config.autosearch;
+    if (query) {
+      if (query.match(/^!param!/)) {
+        var param = query.replace(/^!param!/, '');
+        query = mkws.getParameterByName(param);
+        widget.log("obtained query '" + query + "' from param '" + param + "'");
+        if (!query) {
+          alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter");
+        }
+      } else if (query.match(/^!path!/)) {
+        var index = query.replace(/^!path!/, '');
+        var path = window.location.pathname.split('/');
+        query = path[path.length - index];
+        widget.log("obtained query '" + query + "' from path-component '" + index + "'");
+        if (!query) {
+          alert("This page has a MasterKey widget that needs a query specified by the path-component " + index);
+        }
+      } else if (query.match(/^!var!/)) {
+        var name = query.replace(/^!var!/, '');
+        query = window[name]; // It's ridiculous that this works
+        widget.log("obtained query '" + query + "' from variable '" + name + "'");
+        if (!query) {
+          alert("This page has a MasterKey widget that needs a query specified by the '" + name + "' variable");
+        }
+      }
+
+      var sortOrder = widget.config.sort;
+      var maxrecs = widget.config.maxrecs;
+      var perpage = widget.config.perpage;
+      var limit = widget.config.limit;
+      var targets = widget.config.targets;
+      var targetfilter = widget.config.targetfilter;
+      var target = widget.config.target;
+      if (target) targetfilter = 'udb=="' + target + '"';
+
+      var s = "running auto search: '" + query + "'";
+      if (sortOrder) s += " sorted by '" + sortOrder + "'";
+      if (maxrecs) s += " restricted to " + maxrecs + " records";
+      if (perpage) s += " with " + perpage + " per page";
+      if (limit) s += " limited by '" + limit + "'";
+      if (targets) s += " in targets '" + targets + "'";
+      if (targetfilter) s += " constrained by targetfilter '" + targetfilter + "'";
+      widget.log(s);
+
+      widget.team.newSearch(query, sortOrder, maxrecs, perpage, limit, targets, targetfilter);
+    }
+  });
 };
 
 
 // Utility function for all widgets that want to hide in narrow windows
 widget.hideWhenNarrow = function(widget) {
-    widget.team.queue("resize-narrow").subscribe(function(n) {
-       $(widget.node).hide();
-    });
-    widget.team.queue("resize-wide").subscribe(function(n) {
-       $(widget.node).show();
-    });
+  widget.team.queue("resize-narrow").subscribe(function(n) {
+    $(widget.node).hide();
+  });
+  widget.team.queue("resize-wide").subscribe(function(n) {
+    $(widget.node).show();
+  });
 };