From 7c985fd3bc597f51839e14a98eceaa4cc9b9f492 Mon Sep 17 00:00:00 2001
From: M Parker <mparker17@536298.no-reply.drupal.org>
Date: Tue, 22 Nov 2016 09:05:51 -0500
Subject: [PATCH] 1526020-46

---
 facetapi.js                       | 20 +++++++++++------
 plugins/facetapi/widget_links.inc | 45 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/facetapi.js b/facetapi.js
index 701182e..840d310 100644
--- a/facetapi.js
+++ b/facetapi.js
@@ -9,7 +9,7 @@ Drupal.behaviors.facetapi = {
     if (settings.facetapi) {
       for (var index in settings.facetapi.facets) {
         if (null != settings.facetapi.facets[index].makeCheckboxes) {
-          Drupal.facetapi.makeCheckboxes(settings.facetapi.facets[index].id);
+          Drupal.facetapi.makeCheckboxes(settings.facetapi.facets[index].id, settings.facetapi.facets[index]);
         }
         if (null != settings.facetapi.facets[index].limit) {
           // Applies soft limit to the list.
@@ -74,12 +74,14 @@ Drupal.facetapi.Redirect.prototype.gotoHref = function() {
  * Turns all facet links into checkboxes.
  * Ensures the facet is disabled if a link is clicked.
  */
-Drupal.facetapi.makeCheckboxes = function(facet_id) {
+Drupal.facetapi.makeCheckboxes = function(facet_id, facet_settings) {
   var $facet = $('#' + facet_id),
       $items = $('a.facetapi-checkbox, span.facetapi-checkbox', $facet);
 
   // Find all checkbox facet links and give them a checkbox.
-  $items.once('facetapi-makeCheckbox').each(Drupal.facetapi.makeCheckbox);
+  $items.once('facetapi-makeCheckbox').each(function(index, element) {
+    Drupal.facetapi.makeCheckbox(element, facet_settings);
+  });
   $items.once('facetapi-disableClick').click(function (e) {
     Drupal.facetapi.disableFacet($facet);
   });
@@ -109,8 +111,8 @@ Drupal.facetapi.preventDefault = function (e) {
 /**
  * Replace an unclick link with a checked checkbox.
  */
-Drupal.facetapi.makeCheckbox = function() {
-  var $elem = $(this),
+Drupal.facetapi.makeCheckbox = function(element, facet_settings) {
+  var $elem = $(element),
       active = $elem.hasClass('facetapi-active');
 
   if (!active && !$elem.hasClass('facetapi-inactive')) {
@@ -121,7 +123,7 @@ Drupal.facetapi.makeCheckbox = function() {
   // Derive an ID and label for the checkbox based on the associated link.
   // The label is required for accessibility, but it duplicates information
   // in the link itself, so it should only be shown to screen reader users.
-  var id = this.id + '--checkbox',
+  var id = element.id + '--checkbox',
       description = $elem.find('.element-invisible').html(),
       label = $('<label class="element-invisible" for="' + id + '">' + description + '</label>');
 
@@ -145,7 +147,11 @@ Drupal.facetapi.makeCheckbox = function() {
   if (active) {
     checkbox.attr('checked', true);
     // Add the checkbox and label, hide the link.
-    $elem.before(label).before(checkbox).hide();
+    $elem.before(label).before(checkbox);
+
+    if (!facet_settings.show_active_label) {
+      $elem.hide();
+    }
   }
   else {
     $elem.before(label).before(checkbox);
diff --git a/plugins/facetapi/widget_links.inc b/plugins/facetapi/widget_links.inc
index 902c7b0..f28c027 100644
--- a/plugins/facetapi/widget_links.inc
+++ b/plugins/facetapi/widget_links.inc
@@ -273,4 +273,49 @@ class FacetapiWidgetCheckboxLinks extends FacetapiWidgetLinks {
   public function getItemClasses() {
     return array('facetapi-checkbox');
   }
+
+  /**
+   * {@inheritdoc}
+   */
+  function buildListItems($build) {
+    $this->addShowActiveLabelJsSetting();
+    return parent::buildListItems($build);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function settingsForm(&$form, &$form_state) {
+    parent::settingsForm($form, $form_state);
+
+    // Allow users to choose whether the labels of active checkboxes are hidden.
+    $form['widget']['widget_settings']['links']['facetapi_checkbox_links']['show_active_label'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Show the labels of active checkboxes'),
+      '#default_value' => !empty($this->settings->settings['show_active_label']),
+      '#description' => t('Displays an active item as a checkbox followed by a link.'),
+      '#states' => array(
+        'visible' => array(
+          ':input[name="widget"]' => array('value' => 'facetapi_checkbox_links'),
+        ),
+      ),
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  function getDefaultSettings() {
+    return parent::getDefaultSettings() + array(
+      'show_active_label' => 0,
+    );
+  }
+
+  /**
+   * Copy the show_active_label setting into the JS settings.
+   */
+  private function addShowActiveLabelJsSetting() {
+    $this->jsSettings['show_active_label'] = $this->settings->settings['show_active_label'];
+  }
+
 }
-- 
2.10.2

