X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=75a88c7732ede3629a4134690aa1e3c236c77b2e;hb=d3b27e0d579da1535397fe464b5fb0476f0c0020;hp=72ca3f3220fb785b24b154b908359ce2edd95954;hpb=5a8ded8d2a75ea7b0ca1412ec837d8f33114edbc;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 72ca3f3..75a88c7 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -172,13 +172,15 @@ if (mkws_config == null || typeof mkws_config != 'object') { // 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; } @@ -918,7 +920,7 @@ function team($, teamName) { // ### 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(node, function(tname) { + mkws.handle_node_with_team(this, function(tname) { $(node).html('\
\ \ @@ -988,7 +990,7 @@ function team($, teamName) { $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) { debug("adding search-forms for team '" + m_teamName + "'"); var node = this; - mkws.handle_node_with_team(node, function(tname) { + mkws.handle_node_with_team(this, function(tname) { debug("adding search-form '" + tname + "' for team '" + m_teamName + "'"); $(node).submit(onFormSubmitEventHandler); }); @@ -1238,16 +1240,28 @@ function team($, teamName) { 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(tname); + callback.call(node, teamName, type); } @@ -1441,13 +1455,13 @@ function team($, teamName) { // 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();