From 6069b9f448eca6edf56b8bfbd572fc733effd5a9 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 7 Apr 2014 14:23:20 +0100 Subject: [PATCH] Separate pub/sub event for each facet. Took *a lot* of poxing about to fix the closure-variable error. --- src/mkws-widget-termlists.js | 68 ++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js index e61ea64..7b84311 100644 --- a/src/mkws-widget-termlists.js +++ b/src/mkws-widget-termlists.js @@ -8,44 +8,46 @@ mkws.registerWidgetType('Termlists', function() { $(that.node).show(); }); - this.team.queue("termlists").subscribe(function(data) { - for (var i = 0; i < facets.length; i++) { - var name = facets[i] - var ref = mkws.facetConfig[name]; - var caption = ref[0]; - if (!ref) { - alert("bad facet configuration: '" + name + "'"); - } else { - makeSingleFacet(ref[0], data[name], ref[1], ref[2] ? name : null); - } + for (var i = 0; i < facets.length; i++) { + var name = facets[i] + var ref = mkws.facetConfig[name]; + if (!ref) { + alert("bad facet configuration: '" + name + "'"); + } else { + (function(ref, name) { + var caption = ref[0]; + that.team.queue("termlists").subscribe(function(data) { + makeSingleFacet(caption, data[name], ref[1], ref[2] ? name : null); + }) + }(ref, name)); } + } + + function makeSingleFacet(caption, data, max, pzIndex) { + that.log("in makeSingleFacet(" + caption + ")"); + var teamName = that.team.name(); - - function makeSingleFacet(caption, data, max, pzIndex) { - var teamName = that.team.name(); - - var acc = []; - acc.push('
' + M(caption) + '
'); - for (var i = 0; i < data.length && i < max; i++) { - acc.push('
'); - acc.push('' + M(caption) + '
'); + for (var i = 0; i < data.length && i < max; i++) { + acc.push('
'); + acc.push('' + data[i].name + '' - + ' ' + data[i].freq + ''); - acc.push('
'); + } else { + action = 'mkws.limitQuery(\'' + teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)'; } - that.team.findnode('.mkwsFacet' + caption).html(acc.join('')); + acc.push('onclick="' + action + ';return false;">' + data[i].name + '' + + ' ' + data[i].freq + ''); + acc.push(''); } - }); + that.team.findnode('.mkwsFacet' + caption).html(acc.join('')); + } widget.autosearch(that); }); -- 1.7.10.4