<commit_before>/**
 * @fileOverview Facet building and interaction utilities.
 * @author <NAME>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

/**
 * @namespace
 */
Exhibit.FacetUtilities = {};

/**
 * @static
 * @param {Exhibit.Facet} forFacet
 * @param {Element} div
 * @param {String} facetLabel
 * @param {Function} onClearAllSelections
 * @param {Exhibit.UIContext} uiContext
 * @param {Boolean} collapsible
 * @param {Boolean} collapsed
 * @returns {Object}
 */
Exhibit.FacetUtilities.constructFacetFrame = function(forFacet, div, facetLabel, onClearAllSelections, uiContext, collapsible, collapsed) {
    var dom, resizableDivWidget;

    Exhibit.jQuery(div).addClass("exhibit-facet");
    dom = Exhibit.jQuery.simileDOM("string", div,
            '<div class="exhibit-facet-header">' +
            '<div class="exhibit-facet-header-filterControl" id="clearSelectionsDiv" title="' + Exhibit._("%facets.clearSelectionsTooltip") + '">' +
            '<span id="filterCountSpan"></span>' +
            '<img id="checkImage" />' +
            '</div>' +
            ((collapsible) ?
             '<img src="' + Exhibit.urlPrefix + 'images/collapse.png" class="exhibit-facet-header-collapse" id="collapseImg" />' :
                '') +
            '<span class="exhibit-facet-header-title" id="title">' + facetLabel + '</span>' +
        '</div>' +
        '<div class="exhibit-facet-body-frame" id="frameDiv"></div>',
        { checkImage: Exhibit.UI.createTranslucentImage("images/black-check.png") }
    );
    resizableDivWidget = Exhibit.ResizableDivWidget.create({}, dom.frameDiv, uiContext);
    
    dom.valuesContainer = resizableDivWidget.getContentDiv();
    Exhibit.jQuery(dom.valuesContainer).addClass("exhibit-facet-body");
    
    dom.setSelectionCount = function(count) {
        Exhibit.jQuery(this.filterCountSpan).html(count);
        Exhibit.jQuery(this.clearSelectionsDiv).toggle(count > 0);
    };
    Exhibit.jQuery(dom.clearSelectionsDiv).bind("click", onClearAllSelections);
    
    if (collapsible) {
        Exhibit.jQuery(dom.collapseImg).add(Exhibit.jQuery(dom.title))
            .bind("click", function(evt) {
            Exhibit.FacetUtilities.toggleCollapse(dom, forFacet);
        });
        
        if (collapsed) {
            Exhibit.FacetUtilities.toggleCollapse(dom, forFacet);
        }
    }
    
    return dom;
};

/**
 * @static
 * @param {Object} dom
 * @param {Exhibit.Facet} facet
 */
Exhibit.FacetUtilities.toggleCollapse = function(dom, facet) {
    var el = dom.frameDiv;
    if (Exhibit.jQuery(el).is(":visible")) {
        Exhibit.jQuery(el).hide();
        Exhibit.jQuery(dom.collapseImg).attr("src", Exhibit.urlPrefix + "images/expand.png");
    } else {
        Exhibit.jQuery(el).show();
        Exhibit.jQuery(dom.collapseImg).attr("src", Exhibit.urlPrefix + "images/collapse.png");
		// Try to call onUncollapse but don't sweat it if it isn't there.
		if (typeof facet.onUncollapse === 'function') {
			facet.onUncollapse();			
		}
    }
};

/**
 * @static
 * @param {Exhibit.Facet} facet
 * @returns {Boolean}
 */
Exhibit.FacetUtilities.isCollapsed = function(facet) {
    var el = facet._dom.frameDiv;
    return !Exhibit.jQuery(el).is(":visible");
};

/**
 * @static
 * @param {String} label
 * @param {Number} count
 * @param {String} color A valid CSS color value.
 * @param {Boolean} selected
 * @param {Boolean} facetHasSelection
 * @param {Function} onSelect
 * @param {Function} onSelectOnly
 * @param {Exhibit.UIContext} uiContext
 * @returns {Element}
 */
Exhibit.FacetUtilities.constructFacetItem = function(
    label, 
    count, 
    color,
    selected, 
    facetHasSelection,<commit_msg>fixed facet visibility/collapsibility bug<commit_after>/**
 * @fileOverview Facet building and interaction utilities.
 * @author <NAME>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

/**
 * @namespace
 */
Exhibit.FacetUtilities = {};

/**
 * @static
 * @param {Exhibit.Facet} forFacet
 * @param {Element} div
 * @param {String} facetLabel
 * @param {Function} onClearAllSelections
 * @param {Exhibit.UIContext} uiContext
 * @param {Boolean} collapsible
 * @param {Boolean} collapsed
 * @returns {Object}
 */
Exhibit.FacetUtilities.constructFacetFrame = function(forFacet, div, facetLabel, onClearAllSelections, uiContext, collapsible, collapsed) {
    var dom, resizableDivWidget;

    Exhibit.jQuery(div).addClass("exhibit-facet");
    dom = Exhibit.jQuery.simileDOM("string", div,
            '<div class="exhibit-facet-header">' +
            '<div class="exhibit-facet-header-filterControl" id="clearSelectionsDiv" title="' + Exhibit._("%facets.clearSelectionsTooltip") + '">' +
            '<span id="filterCountSpan"></span>' +
            '<img id="checkImage" />' +
            '</div>' +
            ((collapsible) ?
             '<img src="' + Exhibit.urlPrefix + 'images/collapse.png" class="exhibit-facet-header-collapse" id="collapseImg" />' :
                '') +
            '<span class="exhibit-facet-header-title" id="title">' + facetLabel + '</span>' +
        '</div>' +
        '<div class="exhibit-facet-body-frame" id="frameDiv"></div>',
        { checkImage: Exhibit.UI.createTranslucentImage("images/black-check.png") }
    );
    resizableDivWidget = Exhibit.ResizableDivWidget.create({}, dom.frameDiv, uiContext);
    
    dom.valuesContainer = resizableDivWidget.getContentDiv();
    Exhibit.jQuery(dom.valuesContainer).addClass("exhibit-facet-body");
    
    dom.setSelectionCount = function(count) {
        Exhibit.jQuery(this.filterCountSpan).html(count);
        Exhibit.jQuery(this.clearSelectionsDiv).toggle(count > 0);
    };
    Exhibit.jQuery(dom.clearSelectionsDiv).bind("click", onClearAllSelections);
    
    if (collapsible) {
        Exhibit.jQuery(dom.collapseImg).add(Exhibit.jQuery(dom.title))
            .bind("click", function(evt) {
            Exhibit.FacetUtilities.toggleCollapse(dom, forFacet);
        });
        
        if (collapsed) {
            Exhibit.FacetUtilities.toggleCollapse(dom, forFacet);
        }
    }
    
    return dom;
};

/**
 * @static
 * @param {Object} dom
 * @param {Exhibit.Facet} facet
 */
Exhibit.FacetUtilities.toggleCollapse = function(dom, facet) {
    var el = dom.frameDiv;
    if (Exhibit.jQuery(el).is(":visible")) {
        Exhibit.jQuery(el).hide();
        Exhibit.jQuery(dom.collapseImg).attr("src", Exhibit.urlPrefix + "images/expand.png");
    } else {
        Exhibit.jQuery(el).show();
        Exhibit.jQuery(dom.collapseImg).attr("src", Exhibit.urlPrefix + "images/collapse.png");
		// Try to call onUncollapse but don't sweat it if it isn't there.
		if (typeof facet.onUncollapse === 'function') {
			facet.onUncollapse();			
		}
    }
};

/**
 * @static
 * @param {Exhibit.Facet} facet
 * @returns {Boolean}
 */
Exhibit.FacetUtilities.isCollapsed = function(facet) {
    var el = facet._dom.frameDiv;
    return !Exhibit.jQuery(el).is(":visible") && Exhibit.jQuery(el).attr("ex-collapsible"); //fixes visibility / collapsibility issue
};

/**
 * @static
 * @param {String} label
 * @param {Number} count
 * @param {String} color A valid CSS color value.
 * @param {Boolean} selected
 * @param {Boolean} facetHasSelection
 * @param {Function} onSelect
 * @param {Function} onSelectOnly
 * @param {Exhibit.UIContext} uiContext
 * @returns {Element}
 */
Exhibit.FacetUtilities.constructFacetItem = function(
    label, 
    count, 
    color,
    selected, 
    facetHasSelection,
{'fraction_non_alphanumeric': 0.1579370395177495, 'fraction_numerical': 0.00026791694574681847, 'mean_word_length': 3.3006912442396312, 'pattern_counts': {'":': 4, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3934668', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2361, 'n_words': 413}