Break addSingleFacet into two functions, addSingleScaffold which adds
authorMike Taylor <mike@indexdata.com>
Fri, 4 Apr 2014 15:16:02 +0000 (16:16 +0100)
committerMike Taylor <mike@indexdata.com>
Fri, 4 Apr 2014 15:16:02 +0000 (16:16 +0100)
scaffolding to the main HTML, and makeSingleFacet which returns the
HTML of a specific facet.

src/mkws-widget-termlists.js

index eb299f0..9f98568 100644 (file)
@@ -30,7 +30,8 @@ mkws.registerWidgetType('Termlists', function() {
            if (!ref) {
                alert("bad facet configuration: '" + name + "'");
            } else {
-               output[name] = addSingleFacet(acc, ref[0], data[name], ref[1], ref[2] ? name : null);
+               addSingleScaffold(acc, ref[0], data[name], ref[1], ref[2] ? name : null);
+               output[name] = makeSingleFacet(acc, ref[0], data[name], ref[1], ref[2] ? name : null);
            }
        }
 
@@ -45,9 +46,15 @@ mkws.registerWidgetType('Termlists', function() {
            that.team.findnode('.mkwsFacet' + caption).html(output[name]);
        }
 
-       function addSingleFacet(acc, caption, data, max, pzIndex) {
+       function addSingleScaffold(acc, caption, data, max, pzIndex) {
            var teamName = that.team.name();
            acc.push('<div class="mkwsFacet mkwsFacet' + caption + ' mkwsTeam_' + teamName + '">');
+           acc.push('</div>');
+       }
+
+
+       function makeSingleFacet(acc, caption, data, max, pzIndex) {
+           var teamName = that.team.name();
 
            var a2 = [];
            a2.push('<div class="termtitle">' + M(caption) + '</div>');
@@ -68,7 +75,6 @@ mkws.registerWidgetType('Termlists', function() {
                         + ' <span>' + data[i].freq + '</span>');
                a2.push('</div>');
            }
-           acc.push('</div>');
            return a2.join('');
        }
     });