Merge branch 'master' of ssh://git.indexdata.com:222/home/git/private/mkws
authorHeikki Levanto <heikki@indexdata.dk>
Fri, 28 Feb 2014 12:50:19 +0000 (13:50 +0100)
committerHeikki Levanto <heikki@indexdata.dk>
Fri, 28 Feb 2014 12:50:19 +0000 (13:50 +0100)
1  2 
tools/htdocs/mkws.js

diff --combined tools/htdocs/mkws.js
@@@ -172,13 -172,15 +172,15 @@@ if (mkws_config == null || typeof mkws_
  
  
  // Factory function for widget objects.
- function widget($, team, node) {
+ function widget($, team, type, node) {
      var that = {
        team: team,
+       type: type,
        node: node
      };
  
-     // ### More to do here, surely
+     // ### More to do here, surely: e.g. wiring into the team
+     mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node);
  
      return that;
  }
@@@ -915,16 -917,13 +917,13 @@@ function team($, teamName) 
            mkws_html_lang();
  
        debug("HTML search form");
-       // ### There is only one match here by design: fix not to bother looping
-       $('.mkwsSearch.mkwsTeam_' + m_teamName).each(function (i, obj) {
-           var node = this;
-           mkws.handle_node_with_team(this, function(tname) {
-               $(node).html('\
+       mkws.handle_node_with_team($('.mkwsSearch.mkwsTeam_' + m_teamName),
+                                  function(tname) {
+           this.html('\
  <form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
    <input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + mkws_config.query_width + '" />\
    <input class="mkwsButton mkwsTeam_' + tname + '" type="submit" value="' + M('Search') + '" />\
  </form>');
-           });
        });
  
        debug("HTML records");
            $(document).ready(function() { mkws.resize_page() });
        }
  
-       $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) {
-           debug("adding search-forms for team '" + m_teamName + "'");
-           var node = this;
-           mkws.handle_node_with_team(this, function(tname) {
-               debug("adding search-form '" + tname + "' for team '" + m_teamName + "'");
-               $(node).submit(onFormSubmitEventHandler);
-           });
-       });
+       var node;
+       node = $('.mkwsSearchForm.mkwsTeam_' + m_teamName);
+       if (node.length)
+           node.submit(onFormSubmitEventHandler);
        node = $('.mkwsSort.mkwsTeam_' + m_teamName);
        if (node.length)
            node.change(onSelectDdChange);
        // on first page, hide the termlist
        $(document).ready(function() { $(".mkwsTermlists.mkwsTeam_" + m_teamName).hide(); });
        var motd = $(".mkwsMOTD.mkwsTeam_" + m_teamName);
 -      var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName);
 +        var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName);
        if (motd.length && container.length) {
            // Move the MOTD from the provided element down into the container
            motd.appendTo(container);
  
  
      mkws.handle_node_with_team = function(node, callback) {
-       var classes = node.className;
+       // 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.
+           mkws.debug("handle_node_with_team() called on node with no classes");
+           return;
+       }
        var list = classes.split(/\s+/)
-       var tname;
+       var teamName, type;
        for (var i = 0; i < list.length; i++) {
            var cname = list[i];
            if (cname.match(/^mkwsTeam_/)) {
-               tname = cname.replace(/^mkwsTeam_/, '');
+               teamName = cname.replace(/^mkwsTeam_/, '');
+           } else if (cname.match(/^mkws/)) {
+               type = cname.replace(/^mkws/, '');
            }
        }
-       callback.call(this, tname);
+       callback.call(node, teamName, type);
      }
  
  
        // elements that have the old magic IDs.
        var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",
                    "Results", "Records", "Targets", "Ranking",
 -                  "Termlists", "Stat" ];
 +                  "Termlists", "Stat", "MOTD" ];
        for (var i = 0; i < ids.length; i++) {
            var id = 'mkws' + ids[i];
            var node = $('#' + id);
        // the mkwsTeam_* class. Make all team objects.
        var then = $.now();
        $('[class^="mkws"],[class*=" mkws"]').each(function () {
-           mkws.handle_node_with_team(this, function(tname) {
+           mkws.handle_node_with_team(this, function(tname, type) {
                if (!mkws.teams[tname]) {
                    mkws.teams[tname] = team(j, tname);
                    debug("Made MKWS team '" + tname + "'");
                }
-               var myTeam = mkws.teams[tname]
-               var myWidget = widget(j, myTeam, this)
+               var myTeam = mkws.teams[tname];
+               var myWidget = widget(j, myTeam, type, this);
            });
        });
        var now = $.now();