Ne0nx3r0 / simile-widgets

Automatically exported from code.google.com/p/simile-widgets
0 stars 0 forks source link

Add showFacetCount property to list facet #380

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We made the following changes to list-facet.js and facets.js to enable a new 
list facet property called showFacetCount that, when enabled on a list facet, 
displays the number of items in the facet next to the facet title in 
parentheses.  Here are the changes that were made:

$ diff -b list-facet.js list-facet-new.js
18a19
>     this._facetCount = 0;
33c34,35
<     "formatter":        { type: "text", defaultValue: null}

---
>     "formatter":        { type: "text", defaultValue: null},
>     "showFacetCount":  { type: "boolean", defaultValue: false }
249a252,253
>     this._facetCount = entries.length;
> 
347a352,355
> 
>     if (this._settings.showFacetCount) {
>         this._dom.setFacetCount(this._facetCount);
>     }

$ diff -b facets.js facets-new.js
21c21
<             "<span class='exhibit-facet-header-title'>" + facetLabel + 
"</span>" +

---
>             "<span class='exhibit-facet-header-title'>" + facetLabel + 
"</span> <span id='facetCountSpan'></span>" +
34a35,38
> 
>     dom.setFacetCount = function(count) {
>         this.facetCountSpan.innerHTML = "(" + count + ")";
>     };

Please consider incorporating this change.  Thank you.

Original issue reported on code.google.com by davecrum...@gmail.com on 21 Jul 2010 at 12:58

GoogleCodeExporter commented 9 years ago
I found that if a list facet starts out as collapsed (ex:collapsed="true"), the 
facet count is not displayed.  This is because the list facet is not yet 
populated.  This chanage to Exhibit.ListFacet.prototype.update (in 
list-facet.js) will force an update to the list facet even when collapsed, if 
showFacetCount is true:

Exhibit.ListFacet.prototype.update = function(items) {
    if (!this._settings.showFacetCount && Exhibit.FacetUtilities.isCollapsed(this)) {
        this._delayedUpdateItems = items;
        return;
    }

    this._dom.valuesContainer.style.display = "none";
    this._dom.valuesContainer.innerHTML = "";
    this._constructBody(this._computeFacet(items));
    this._dom.valuesContainer.style.display = "block";
};

The single change is the addition of "!this._settings.showFacetCount &&" in the 
first line of the update function.

Original comment by davecrum...@gmail.com on 30 Jul 2010 at 4:33

GoogleCodeExporter commented 9 years ago

Original comment by ryan...@csail.mit.edu on 23 Jun 2011 at 9:47