X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget-termlists.js;h=33d12b92255e538a33188256a7d8a93ca629ceda;hb=383378d6a66b3b00bb540e2c1738d18d470b557e;hp=b140198f0e338f8cecf0e62d96fcc969f7dcb247;hpb=bc2d7408d42b07d00924082cb719a44ff1175e4e;p=mkws-moved-to-github.git
diff --git a/src/mkws-widget-termlists.js b/src/mkws-widget-termlists.js
index b140198..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;
- mkws.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 = mkws.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 = mkws.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('');
+ for (var i = 0; i < data.length && i < max; i++) {
+ 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(''));
+ });
});