X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-termlists.js;h=33d12b92255e538a33188256a7d8a93ca629ceda;hb=b75f69516de319ca5c283a70238a482e86303138;hp=db36c662c17cfb5c04aff8d6c561ff96ff82fd1b;hpb=9ea6b8571266796b8410c320a39be15d8ee830cc;p=mkws-moved-to-github.git diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js index db36c66..33d12b9 100644 --- a/src/mkws-widget-termlists.js +++ b/src/mkws-widget-termlists.js @@ -1,71 +1,64 @@ mkws.registerWidgetType('Termlists', function() { var that = this; - var facets = that.config.facets; - var M = mkws.M; - var facetConfig = { - xtargets: [ "Sources", 16, false ], - subject: [ "Subjects", 10, true ], - author: [ "Authors", 10, true ] - } + // 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 = []; - acc.push('
' + M('Termlists') + '
'); + var facets = this.config.facets; + acc.push('
' + mkws.M('Termlists') + '
'); for (var i = 0; i < facets.length; i++) { - var name = facets[i] - var ref = facetConfig[name]; - if (!ref) { - alert("bad facet configuration: '" + name + "'"); - } else { - acc.push('
'); - acc.push('
'); - } + acc.push('
', '
'); } - $(that.node).html(acc.join('')); + $(this.node).html(acc.join('')); + widget.autosearch(this); +}); - this.team.queue("termlists").subscribe(function(data) { - // display if we first got results - $(that.node).show(); - for (var i = 0; i < facets.length; i++) { - var name = facets[i] - var ref = facetConfig[name]; - var caption = ref[0]; - if (!ref) { - alert("bad facet configuration: '" + name + "'"); - } else { - var output = makeSingleFacet(ref[0], data[name], ref[1], ref[2] ? name : null); - that.team.findnode('.mkwsFacet' + caption).html(output); - } - } +mkws.registerWidgetType('Facet', function() { + 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; - function makeSingleFacet(caption, data, max, pzIndex) { - var teamName = that.team.name(); + that.team.queue("termlists").subscribe(function(data) { + data = data[name]; - var acc = []; - acc.push('
' + M(caption) + '
'); - for (var i = 0; i < data.length && i < max; i++) { - acc.push('
'); - acc.push('' + mkws.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)'; } - return acc.join(''); + acc.push('onclick="' + action + ';return false;">' + data[i].name + '' + + ' ' + data[i].freq + ''); + acc.push(''); } - }); - widget.autosearch(that); + $(that.node).html(acc.join('')); + }); });